Skip to content

How to set div border in HTML | Example adding a border to a div

  • by

You have to use CSS and border property to set div border in HTML.

Explicit about all the border properties. Like width, type and color.

Shorthand

border:1px solid black;

Note: Browsers don’t set the width or color to a default you’d expect.

Example of How to set div border in HTML

It’s an inline CSS example you can do it with Internal or External CSS, using id or class.

<!DOCTYPE html>
<html>
<head>
    
</head>
<body>
    <div id="divActivites" name="divActivites" style="border:1px solid black;">

    <textarea id="inActivities" name="inActivities" style="border:2px solid green;">

    </textarea> 
</div> 
</body>
</html>

Output:

How to set div border in HTML

Another way you can use it:

border-width:2px;
border-style:solid;
border-color:black;

How to add a border to a div

Use CSS border properties and specify the style, width, and color of an element’s border.

border:1px solid black;

Do comment if you have any doubts and suggestions on this topic.

Note: The All HTML Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *