![CSS Selectors](https://codetofun.com/wp-content/themes/codetofun/images/large/css-selectors.webp)
CSS Properties
CSS outline-width Property
![CSS outline-width Property](https://codetofun.com/wp-content/themes/codetofun/images/large/css-outline-width.webp)
Photo Credit to CodeToFun
🙋 Introduction
The outline-width
property in CSS is used to define the thickness of the outline of an element. Unlike borders, outlines do not take up space in the layout and are drawn outside the element's border edge.
This property is useful for highlighting elements, creating focus states, or adding visual emphasis to specific parts of a webpage.
💡 Syntax
The syntax for the outline-width
property is simple and can be used with various values to control the thickness of the outline.
element {
outline-width: width;
}
Here, width specifies the thickness of the outline and can be one of the following values.
🎛️ Default Value
The default value of the outline-width
property is medium, which is a browser-defined width that varies between browsers but is generally considered a standard medium thickness.
🏠 Property Values
Value | Description |
---|---|
thin | A thin outline. The exact width is defined by the browser. |
medium | A medium outline. The exact width is defined by the browser. |
thick | A thick outline. The exact width is defined by the browser. |
length | A specific width defined using units such as px, em, rem, etc. For example, 2px or 0.1em. |
📄 Example
In this example, we'll set the outline width of a button to thick.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS outline-width Example</title>
<style>
button {
outline: solid black;
outline-width: thick;
}
</style>
</head>
<body>
<h1>Button with Custom Outline Width</h1>
<button>Click Me</button>
</body>
</html>
Example with Specific Length
In this example, we'll set the outline width of an input field to 3px.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS outline-width Example</title>
<style>
input[type="text"] {
outline: dashed blue;
outline-width: 3px;
}
</style>
</head>
<body>
<h1>Input Field with Custom Outline Width</h1>
<input type="text" placeholder="Type something...">
</body>
</html>
🖥️ Browser Compatibility
The outline-width
property is well-supported in all modern browsers, including Chrome, Firefox, Safari, Edge, and Opera. This makes it a reliable choice for styling outlines consistently across different platforms.
🎉 Conclusion
The outline-width
property provides a simple and effective way to control the thickness of outlines on elements.
By using this property, you can enhance the visual emphasis of your webpage elements, making them more noticeable or helping to create a cohesive design. Experiment with different values to find the perfect thickness for your design needs.
👨💻 Join our Community:
Author
![author](https://codetofun.com/wp-content/themes/codetofun/images/mari-selvan-400.webp)
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (CSS outline-width Property), please comment here. I will help you immediately.