CSS Padding Property: Complete Guide with Syntax and Examples

calender-iconPublished: 27 Jun 2025

clock-icon5-min read





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.
Example:

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?
In CSS, outline: none; means no outline will be drawn around the element. It removes the default outline that browsers often show, especially on elements like buttons or input fields when they are focused.

Can I make an outline rounded in CSS?
By default, outlines in CSS cannot be rounded directly using border-radius. The outline is drawn outside the border edge, and it does not follow border-radius rules like borders do.

Is outline part of the box model in CSS?
No, the outline is not part of the CSS box model. The CSS box model consists of:
  • content
  • padding
  • border
  • margin
The outline is outside the border, but unlike margin, it does not take up space and does not affect layout or box size.

How to add an outline on hover in CSS?
To add an outline on hover in CSS, use the :hover pseudo-class. This class targets the element when the mouse is over it. ✅ Example:


button:hover {
  outline: 2px solid #007bff;
 }

How to remove outline around text/input boxes?
To remove the outline around text or input boxes in CSS, you can use the outline: none property. Most browsers add an outline only when the element is focused for accessibility. If you're targeting focus, do this:


input:focus {
  outline: none;
}