Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Set a dotted line for the border with CSS
To set a dotted line for the border in CSS, use the border-style property with the value dotted. This creates a border made up of small dots around the element.
Syntax
border-style: dotted;
Example
Here's how to create a dotted border using CSS:
<html>
<head>
<style>
.dotted-border {
border-width: 3px;
border-style: dotted;
padding: 10px;
margin: 10px;
}
</style>
</head>
<body>
<p class="dotted-border">
This is a dotted border.
</p>
</body>
</html>
Different Border Widths
You can control the thickness of the dotted border by adjusting the border-width property:
<html>
<head>
<style>
.thin-dotted { border: 1px dotted #333; padding: 5px; }
.medium-dotted { border: 3px dotted #666; padding: 5px; }
.thick-dotted { border: 5px dotted #999; padding: 5px; }
</style>
</head>
<body>
<div class="thin-dotted">Thin dotted border (1px)</div><br>
<div class="medium-dotted">Medium dotted border (3px)</div><br>
<div class="thick-dotted">Thick dotted border (5px)</div>
</body>
</html>
Partial Dotted Borders
You can apply dotted borders to specific sides of an element:
<html>
<head>
<style>
.partial-borders {
border-top: 2px dotted red;
border-bottom: 2px dotted blue;
padding: 15px;
margin: 10px;
}
</style>
</head>
<body>
<div class="partial-borders">
Only top and bottom borders are dotted.
</div>
</body>
</html>
Browser Compatibility
The border-style: dotted property is supported by all major browsers including Chrome, Firefox, Safari, Edge, and Internet Explorer. The appearance may vary slightly between browsers.
Conclusion
Use border-style: dotted to create dotted borders in CSS. Combine with border-width and border-color for complete control over the border appearance.
Advertisements
