CSS BORDERS /// BORDER-RADIUS /// BORDER-STYLE /// OUTLINE /// CSS BORDERS /// BORDER-RADIUS /// BORDER-STYLE /// OUTLINE ///

CSS Borders

Define the boundaries of your elements. Master borders, perfect circles with border-radius, and accessibility outlines.

borders.css
1 / 16
12345
🖼️

Tutor:Every HTML element is a box. Borders allow us to draw lines around these boxes, controlling their boundaries and style.


Skill Matrix

UNLOCK NODES BY MASTERING BOX BOUNDARIES.

Concept: Border Shorthand

The border property allows you to define the width, style, and color of the border in a single line.

System Check

Which property is absolutely REQUIRED for a border to be visible?


Community Holo-Net

Showcase Your UI Elements

ACTIVE

Created a wild button with crazy border-radius combinations? Share your codepens and get feedback!

CSS Borders: Boxing your Layouts

Author

Pascual Vila

Frontend Instructor // Code Syllabus

Borders are the defining lines of the CSS Box Model. They separate elements, provide structure, and guide the user's eye. Mastering borders means mastering the geometry of the web.

The Foundation: Border Properties

A border consists of three distinct components: its width, its style, and its color. If you are missing the border-style, the border simply won't appear.

  • Style: Can be solid, dashed, dotted, double, groove, ridge, inset, or outset.
  • Width: Accepts specific values like px, rem, or keywords like thin, medium, thick.
  • Color: Any valid CSS color format (hex, rgb, named, hsl).

The Shorthand Syntax

To keep your CSS clean and readable, you will almost exclusively use the shorthand border property. It combines all three aspects into a single line.

border: 2px solid black;
border-bottom: 4px dashed red;

You can also target specific sides of the element using border-top, border-right, border-bottom, and border-left.

Rounding Corners: Border Radius

The border-radius property allows you to soften the edges of your boxes. It doesn't just round the border line; it rounds the background and the clipping area of the box itself.

You can supply up to 4 values to target individual corners (Top-Left, Top-Right, Bottom-Right, Bottom-Left), or use a percentage like 50% on a square element to create a perfect circle.

View Accessibility Tip: Outlines+

Never remove outlines without a replacement! outline is similar to border, but it's drawn *outside* the box model and doesn't affect layout. Browsers use outlines to show keyboard focus (when a user tabs to a button or link). If you set outline: none; for aesthetics, you MUST provide an alternative visual focus state (like a box-shadow or an explicit border change), otherwise keyboard users won't know where they are on the page.

Frequently Asked Questions

Why doesn't my border show if I set width and color?

Because by default, the `border-style` property has the value `none`. You must explicitly tell the browser what type of line you want to draw (for example, `solid`, `dashed`, etc.).

What's the difference between border and outline?

Border: Is part of the Box Model. It adds size to the element's total width and height (if you use `box-sizing: content-box`).

Outline: Draws *outside* the border. It takes no space and doesn't push other elements, making it ideal for `:focus` states. You can also distance it using the `outline-offset` property.

How do I set different border-radius for each corner?

You can pass up to 4 values to the `border-radius` property. The order starts at the top-left and goes clockwise: `Top-Left`, `Top-Right`, `Bottom-Right`, `Bottom-Left`.

/* Top-Left Top-Right Bottom-Right Bottom-Left */
border-radius: 10px 5px 20px 0;

Borders Glossary

border
Shorthand property to set border-width, border-style, and border-color in one declaration.
snippet.css
border-style
Specifies what kind of line to display. Without this, no border is drawn.
snippet.css
border-radius
Rounds the corners of an element's outer border edge.
snippet.css
outline
A line drawn outside the element's border, widely used for accessibility focus states.
snippet.css
border-width
Sets the thickness of the border. Can use px, rem, em, or thin/medium/thick.
snippet.css
border-[side]
Target specific sides using -top, -right, -bottom, or -left.
snippet.css