Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS outline-width Property

Posted in CSS Tutorial
Updated on Oct 07, 2024
By Mari Selvan
👁️ 11 - Views
⏳ 4 mins
💬 1 Comment
CSS outline-width Property

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.

Syntax
Copied
Copy To Clipboard
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

ValueDescription
thinA thin outline. The exact width is defined by the browser.
mediumA medium outline. The exact width is defined by the browser.
thickA thick outline. The exact width is defined by the browser.
lengthA 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.

index.html
Copied
Copy To Clipboard
<!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.

index.html
Copied
Copy To Clipboard
<!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:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

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

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy