CHAPTER 13

CSS Outline

Learn how to add an outline around an element without affecting its layout dimensions.

01. What is CSS Outline?

An outline is a line drawn around an element.
Unlike a border, an outline does not take up space in the normal layout.
Outline is useful for focus states and visual highlighting.

02. Syntax

selector { outline: width style color; }

03. Example

CSS / HTML Example AIFA Coding Lab
<!DOCTYPE html>
<html>
<head>

<style>

input {

    padding: 12px;

    border: 1px solid #999;

}

input:focus {

    outline: 3px solid #38bdf8;

}

</style>

</head>

<body>

<input type="text" placeholder="Click here">

</body>
</html>

04. Important Points

✓ outline-width controls thickness.
✓ outline-style controls the outline style.
✓ outline-color controls the color.
✓ outline does not normally affect element dimensions.
✓ Focus outlines are important for accessibility.

05. Common Mistakes

⚠ Removing focus outlines without providing another visible focus style.
⚠ Confusing outline with border.
⚠ Using an outline that has poor contrast.

06. Real World Use

Outlines are commonly used on focused input fields, buttons and interactive elements.

Ready to Practice? 🚀

Open the AIFA CSS Editor and practice this chapter live.

Try It Yourself →
Practice Exercise

Create a Focus Effect

Create an input field and add a colored outline when the user clicks inside it.