DEV Community

Cover image for CSS Outlines
HyperCode for Devwares

Posted on • Edited on • Originally published at devwares.com

CSS Outlines

CSS Outlines

CSS outlines are lines that are drawn around elements, outside the borders. Outlines are similar to borders, but they differ in a few significant ways:

  • Outlines do not take up space.
  • Outlines can be non-rectangular.

Outlines are defined by the following properties:

Outline Style

The outline-style property is used to specify the style of the outline. It can take the following values: none, dotted, dashed, solid, double, groove, ridge, inset, outset.

p {  outline-style: solid;}
Enter fullscreen mode Exit fullscreen mode

In this example, the outline style of the p element is set to solid.

Outline Color

The outline-color property is used to specify the color of the outline.

p {  outline-color: red;}
Enter fullscreen mode Exit fullscreen mode

In this example, the outline color of the p element is set to red.

Outline Width

The outline width property is used to specify the width of the outline. The width is specified in either length units (like px, em, etc.) or by using one of the three pre-defined values: thin, medium, or thick.

p {  outline-width: 2px;}
Enter fullscreen mode Exit fullscreen mode

In this example, the outline width of the p element is set to 2 pixels.

Outline Offset

The outline-offset property is used to specify the space between an outline and the edge or border of an element. The offset is specified in length units.

p {  outline-offset: 15px;}
Enter fullscreen mode Exit fullscreen mode

In this example, the outline offset of the p element is set to 15 pixels.

Shorthand Property: Outline

The outline property is a shorthand property for setting outline-width, outline-style, and outline-color in a single declaration. If one of the three properties is not specified, the default value will be used.

p {  outline: 2px solid red;}
Enter fullscreen mode Exit fullscreen mode

In this example, the p element is given a red, solid outline that is 2 pixels wide.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Instrument, monitor, fix: a hands-on debugging session

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️