Skip to content
Justice Tech School

Borders

The border-style property is required for a border to show: solid, dashed, dotted, double and more. border-width and border-color finish the job. The shorthand border: 2px solid red sets all three.

You can style one side at a time with border-top, border-right, border-bottom and border-left, which is great for underlines and dividers.

Example
<style>
  div { padding: 10px; margin-bottom: 10px; }
  .a { border: 3px solid #0ea5e9; }
  .b { border: 3px dashed #f97316; }
  .c { border-bottom: 4px double #16a34a; }
  .d { border-left: 8px solid #a855f7; background: #f5f3ff; }
</style>
<div class="a">Solid</div>
<div class="b">Dashed</div>
<div class="c">Bottom only</div>
<div class="d">Accent left border</div>

Exercise

Give the box a 2px solid black border.

.box {
  border: 2px  black;
}

Quiz Test

Which value is needed for a border to appear?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.