Set outline style as a dotted line with CSS

The CSS outline-style property is used to define the style of an element's outline. When set to dotted, it creates a dotted line around the element's border edge.

Syntax

selector {
    outline-style: dotted;
}

Example

The following example demonstrates how to create a dotted outline around a paragraph element −

<!DOCTYPE html>
<html>
<head>
<style>
    .dotted-outline {
        outline-width: 7px;
        outline-style: dotted;
        outline-color: #333;
        padding: 20px;
        margin: 20px;
        background-color: #f0f0f0;
    }
</style>
</head>
<body>
    <p class="dotted-outline">
        This text is having 7px dotted outline.
    </p>
</body>
</html>
A paragraph with gray background and a thick dotted outline appears on the page. The dotted line forms a border around the entire paragraph element.

Conclusion

The outline-style: dotted property creates a dotted line outline around elements. Unlike borders, outlines don't affect the element's dimensions and are drawn outside the border edge.

Updated on: 2026-03-15T11:20:04+05:30

253 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements