Tillitsdone
down Scroll to discover

CSS outline-offset Control Element Outlines

CSS outline-offset controls the space between an element's outline and its border.

Use it for focus indicators and decorative purposes.

Set with pixels, ems, or percentages.
thumbnail

Introduction

The outline-offset property in CSS is a handy tool for controlling the space between an element’s outline and its border. It’s great for enhancing the visual appeal and user experience of your web designs without affecting the page layout.

Specification

The outline-offset property is part of the CSS Basic User Interface Module Level 4. This module provides properties and values for controlling the user interface aspects of web elements, including outlines and their offsets.

Description

The outline-offset property specifies the space between an element’s outline and its border. Unlike borders, outlines don’t affect the layout of the page and can overlap other elements. This makes them ideal for focus indicators and decorative purposes.

Syntax

The syntax for the outline-offset property is straightforward:

outline-offset: <length>;

Where <length> can be any valid CSS length value like pixels (px), ems (em), or other units. You can also use global CSS values like inherit, initial, revert, revert-layer, and unset.

Values

The primary value for outline-offset is a length, which can be specified in various units:

  • Pixels (px): Specifies the space in pixels.
  • Ems (em): Specifies the space relative to the font size of the element.
  • Percentages (%): Specifies the space as a percentage of the element’s size.

You can also use negative values to place the outline inside the element:

outline-offset: -5px;

A value of 0 means there is no space between the element and its outline:

outline-offset: 0;

Global values like inherit, initial, revert, revert-layer, and unset can also be used:

outline-offset: inherit;
outline-offset: initial;
outline-offset: revert;
outline-offset: revert-layer;
outline-offset: unset;

Formal Definition

  • Initial Value: The default value for outline-offset is 0.
  • Applies To: All elements.
  • Inherited: No.
  • Animatable: Yes, as a length.

Examples

Here are some examples to illustrate how outline-offset works:

Setting Outline Offset in Pixels

HTML:

<p>Gallia est omnis divisa in partes tres.</p>

CSS:

p {
outline: 1px dashed red;
outline-offset: 10px;
background: yellow;
border: 1px solid blue;
margin: 15px;
}

This creates a paragraph with a dashed red outline 10 pixels away from the element’s border.

Using Ems for Outline Offset

HTML:

<div class="example">This is an example with ems.</div>

CSS:

.example {
outline: 2px solid green;
outline-offset: 0.5em;
background: lightgray;
border: 1px solid black;
margin: 20px;
padding: 10px;
}

This creates a div with a solid green outline 0.5em away from the element’s border.

Negative Outline Offset

HTML:

<div class="negative-offset">This is an example with a negative offset.</div>

CSS:

.negative-offset {
outline: 2px solid purple;
outline-offset: -5px;
background: lightblue;
border: 1px solid darkblue;
margin: 20px;
padding: 10px;
}

This creates a div with a solid purple outline 5 pixels inside the element’s border.

Zero Outline Offset

HTML:

<div class="zero-offset">This is an example with zero offset.</div>

CSS:

.zero-offset {
outline: 2px solid orange;
outline-offset: 0;
background: lightyellow;
border: 1px solid brown;
margin: 20px;
padding: 10px;
}

This creates a div with a solid orange outline right next to the element’s border.

Using outline-offset

The outline-offset property is a versatile tool for enhancing the visual appeal of your web designs. Here are some practical tips:

Understanding the Basics

  1. Default Behavior: By default, the outline is rendered right outside the element’s border.
  2. Positive and Negative Values: Use positive values to add space between the border and the outline, and negative values to place the outline inside the element.
  3. Zero Value: A value of 0 means no space between the element and its outline.

Practical Applications

  • Focus Indicators: Use outlines with offsets for focus indicators to improve accessibility.
  • Decorative Purposes: Create visually appealing elements without affecting the page layout.

By using the outline-offset property effectively, you can create visually distinct and user-friendly web designs.

Using Outline and Outline-Offset in CSS

  1. Focus Indicators: Outlines help users navigate through interactive elements like buttons, links, and form fields. Adjust outline-offset to make these indicators more visible and user-friendly.

    a:focus {
    outline: 2px solid blue;
    outline-offset: 5px;
    }
  2. Decorative Elements: Outlines can highlight important sections of your web page. Use outline-offset to create visually appealing designs.

    .highlight {
    outline: 3px dashed red;
    outline-offset: 10px;
    }
  3. Responsive Design: Use relative units like em or rem with outline-offset to make your designs responsive.

    .responsive-outline {
    outline: 2px solid green;
    outline-offset: 0.5em;
    }

Best Practices

  1. Consistency: Keep your use of outlines and their offsets consistent for a cohesive look.
  2. Accessibility: Ensure outlines are visible and easy to distinguish, using high-contrast colors and appropriate offsets.
    .accessible-outline {
    outline: 2px solid #000;
    outline-offset: 5px;
    }
  3. Performance: Avoid excessive values or complex styles that could impact performance.
  4. Testing: Test designs across different browsers and devices for consistent behavior.

Combining Outline and Outline-Offset

HTML:

<div class="custom-outline">
This is an element with a custom outline and offset.
</div>

CSS:

.custom-outline {
border: 1px solid steelblue;
outline: 5px solid lightblue;
outline-offset: 10px;
padding: 25px;
margin: 20px;
background: lightgray;
}

Browser Compatibility

The outline-offset property is widely supported across modern browsers:

BrowserVersionRelease Date
Chrome4.0Jan 2010
Firefox3.5Jun 2009
IE/Edge15.0Apr 2017
Opera10.5Mar 2010
Safari3.1Mar 2008

See Also

To further enhance your designs, explore these related properties:

  • [outline]WebsiteUrl: Shorthand for setting all outline properties.
  • [outline-width]WebsiteUrl: Specifies the width of the outline.
  • [outline-style]WebsiteUrl: Specifies the style of the outline.
  • [outline-color]WebsiteUrl: Specifies the color of the outline.
  • [border]WebsiteUrl: Property for setting the border of an element.

By understanding and using these properties, you can create highly customized and visually appealing web designs.

icons/logo-tid.svg Latest Blogs
Discover our top articles, selected to support the growth of your business.
https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R43_Sep_1440x697.jpg@webp สร้างเว็บไซต์ 1 เว็บ ต้องใช้งบเท่าไหร่? เจาะลึกทุกองค์ประกอบ website development cost อยากสร้างเว็บไซต์แต่ไม่มั่นใจในเรื่องของงบประมาณ อ่านสรุปเจาะลึกตั้งแต่ดีไซน์, ฟังก์ชัน และการดูแล พร้อมตัวอย่างงบจริงจาก Till it&#8217;s done ที่แผนชัด งบไม่บานปลายแน่นอน https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R42_Sep_1440x697.jpg@webp Next.js สอน 14 ขั้นตอนเบื้องต้น: สร้างโปรเจกต์แรกใน 30 นาที เริ่มต้นกับ Next.js ใน 14 ขั้นตอนเพียงแค่ 30 นาที พร้อม SSR/SSG และ API Routes ด้วยตัวอย่างโค้ดง่าย ๆ อ่านต่อเพื่อสร้างโปรเจ็กต์แรกได้ทันทีที่นี่ https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R41_Sep_1440x697.jpg@webp วิธีสมัคร Apple Developer Account เพื่อนำแอปขึ้น App Store ทีละขั้นตอน อยากปล่อยแอปบน App Store ระดับโลก มาอ่านคู่มือสมัคร Apple Developer Account พร้อมเคล็ดลับ TestFlight และวิธีอัปโหลดที่ง่ายในบทความเดียวนี้ได้เลย https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F10%2FTill-its-done_SEO_R38_Sep_1440x697.jpg@webp TypeScript Interface คืออะไร? อธิบายพร้อมวิธีใช้และข้อแตกต่างจาก Type เรียนรู้วิธีใช้ TypeScript Interface เพื่อสร้างโครงสร้างข้อมูลที่ปลอดภัยและเข้าใจง่าย พร้อมเปรียบเทียบข้อดีข้อแตกต่างกับ Type ที่คุณต้องรู้ ถูกรวมเอาไว้ในบทความนี้แล้ว https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R36_Sep_1440x697.jpg@webp Material-UI (MUI) คืออะไร อยากสร้าง UI สวยงามและเป็นมืออาชีพในเวลาอันรวดเร็วใช่ไหม มาทำความรู้จักกับ Material-UI (MUI) ที่ช่วยให้คุณพัฒนาแอปพลิเคชันบน React ได้ง่ายและดูดีในทุกอุปกรณ์ https://imgproxy-landing-page.tillitsdone.com/sig/rs:fit:1200:630/plain/https%3A%2F%2Fcms-r2.tillitsdone.com%2Fwp-content-prod%2Fuploads%2F2025%2F09%2FTill-its-done_SEO_R27_Sep_1440x697.jpg@webp เปรียบเทียบ 3 วิธีติดตั้ง install node js บน Ubuntu: NVM vs NodeSource vs Official Repo แบบไหนดีที่สุด? เรียนรู้วิธีติดตั้ง Node.js บน Ubuntu ด้วย NVM, NodeSource หรือ Official Repo เลือกวิธีที่เหมาะกับความต้องการของคุณ พร้อมเปรียบเทียบ เพื่อการพัฒนาที่มีประสิทธิภาพ!
icons/logo-tid.svg

Talk with CEO

Ready to bring your web/app to life or boost your team with expert Thai developers?
Contact us today to discuss your needs, and let’s create tailored solutions to achieve your goals. We’re here to help at every step!
🖐️ Contact us
down Explore our best articles, cover a wide variety of technologies
Our knowledge base
196 Articles
Explore right
icons/logo-react.svg ReactJs
Popular JavaScript library for building user interfaces with a component-based architecture.
160 Articles
Explore right
icons/flutter.svg Flutter
UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase.
144 Articles
Explore right
icons/logo-nodejs.svg Nodejs
JavaScript runtime for building scalable, high-performance server-side applications.
58 Articles
Explore right
icons/next-js.svg Nextjs
React framework enabling server-side rendering and static site generation for optimized performance.
38 Articles
Explore right
icons/tailwind.svg TailwindCSS
Utility-first CSS framework for rapid UI development.
36 Articles
Explore right
icons/code-outline.svg Typescript
Superset of JavaScript adding static types for improved code quality and maintainability.
126 Articles
Explore right
icons/code-outline.svg Golang
Programming language known for its simplicity, concurrency model, and performance.
67 Articles
Explore right
icons/code-outline.svg AstroJs
Astro is an all-in-one web framework. It includes everything you need to create a website, built-in.
38 Articles
Explore right
icons/code-outline.svg Jest
Versatile testing framework for JavaScript applications supporting various test types.
16 Articles
Explore right
icons/code-outline.svg Website development th
11 Articles
Explore right
icons/code-outline.svg Mobile application th
5 Articles
Explore right
icons/code-outline.svg Reactjs th
4 Articles
Explore right
icons/code-outline.svg Nextjs th
3 Articles
Explore right
icons/code-outline.svg Flutter th
1 Articles
Explore right
icons/code-outline.svg Software house th
1 Articles
Explore right
icons/code-outline.svg Nodejs th
1 Articles
Explore right
icons/code-outline.svg Typescript th
337 Articles
Explore right
icons/css-4.svg CSS
CSS3 is the latest version of Cascading Style Sheets, offering advanced styling features like animations, transitions, shadows, gradients, and responsive design.
Let's keep in Touch
Thank you for your interest in Tillitsdone! Whether you have a question about our services, want to discuss a potential project, or simply want to say hello, we're here and ready to assist you.
We'll be right here with you every step of the way.
Contact Information
rick@tillitsdone.com+66824564755
Find All the Ways to Get in Touch with Tillitsdone - We're Just a Click, Call, or Message Away. We'll Be Right Here, Ready to Respond and Start a Conversation About Your Needs.
Address
9 Phahonyothin Rd, Khlong Nueng, Khlong Luang District, Pathum Thani, Bangkok Thailand
Visit Tillitsdone at Our Physical Location - We'd Love to Welcome You to Our Creative Space. We'll Be Right Here, Ready to Show You Around and Discuss Your Ideas in Person.
Social media
FacebookInstagramLinkedIn
Connect with Tillitsdone on Various Social Platforms - Stay Updated and Engage with Our Latest Projects and Insights. We'll Be Right Here, Sharing Our Journey and Ready to Interact with You.
We anticipate your communication and look forward to discussing how we can contribute to your business's success.
We'll be here, prepared to commence this promising collaboration.
Frequently Asked Questions
Explore frequently asked questions about our products and services.
Whether you're curious about features, warranties, or shopping policies, we provide comprehensive answers to assist you.