Table of Contents
INTRODUCTION
An outline is a line drawn around the outside of an element's border. It is an sort of decoration element as it doesn't take up any space (although visible), so it doesn't push or move anything around in the layout. Outlines are often used to highlight elements, especially when they’re focused (like when a user clicks or tabs into a form input).
In CSS, both outline and border are used to draw lines around elements, but they work differently. A border is part of the element’s box and takes up space, which means it can affect the layout of the page. On the other hand, an outline appears outside the border and does not take up space.
CSS outline property
The CSS outline property is an shorthand property which can define the color, style and width of ouline with a single declaration. It is shorthand for the following CSS properties listed:
Syntax:
outline: [outline-width] [outline-style] [outline-color];
Syntax Guidelines
- You don’t have to write properties in any special order. The browser will figure it out.
- You can write the outline property using one, two, or three values
- outline-width: If you don’t set it, the browser uses a medium thickness.
- outline-style: If you don’t set it, there will be no outline.
- outline-color: If not set, the browser will use currentColor.
outline: solid; /* only style */
outline: solid red; /* style + color */
outline: 2px solid blue; /* width + style + color */
outline: red solid 2px; /* color + style + width (valid) */
CSS outline vs border
In CSS, both outline and border draw lines around elements, but are very different from each other. Here's a simple comparison between CSS outline and border:
| Feature | Outline | Border |
|---|---|---|
| Position | Drawn outside the element's border box | Drawn inside the element's box |
| Takes Space | Does not affect layout | Does affect layout (takes up space) |
| Can be Rounded | ❌ Cannot follow border-radius |
✅ Can be rounded with border-radius |
| Individual Sides | ❌ One outline only | ✅ Can set each side (border-top, etc.) |
| Use Case | Accessibility (focus ring), temporary highlights | Design, layout, permanent visual borders |
| CSS Shorthand | outline: style color width; |
border: width style color; |
Frequently Asked Questions (FAQ)
What does outline: none mean in CSS?
Can I make an outline rounded in CSS?
Is outline part of the box model in CSS?
- content
- padding
- border
- margin
How to add an outline on hover in CSS?
button:hover {
outline: 2px solid #007bff;
}
How to remove outline around text/input boxes?
input:focus {
outline: none;
}