CSS Tutorial: Outline and Outline Offset

Kevin Powell · Beginner ·🛠️ AI Tools & Apps ·9y ago

Key Takeaways

Creates a CSS outline and outline offset for website development

Full Transcript

hi there my name is Kevin and here at my channel we learned how to make the web and how to make it look good while we're at it with a new video every Wednesday today we're going to be looking at a little coding quickie we're going to be looking at the CSS property that I didn't know about for the longest time but which I really love now the name about it outline the outline is fantastic for a nice little extra touches from the design of our sites and it's a lot like the border property but it has a few big differences so I've set up this code pen as so I'm going to share the link to this in the description below you can come in here and play around with it if ever you want to so the first thing I wanna look at then one of the cool things with the outline is it goes after the border so we always have our border that goes as far out all the way on the edges so let's set one of those up on my box here so we'll just do a nice simple border let's say five pixels solid black and I get a border all the way around my box I'm assuming you guys know how that works so if I come in here and I give myself an outline and let's do five pixels solid and we'll do red just so we can really see it and there you go after my border I get that red outline that comes in there so that's nice that I can sort of give myself a double border like that so that's really neat one of the first big differences that you'll see is that with a border we can specify what side we want to be working on so instead of doing border like that I can say border bottom and have a border only on my bottom I can't do that with an outline outline won't work that way so if I do outline bottom it's just not going to work there's no outline bottom left right or top it has to go on all four sides so you might be sort of wondering what the point of it is now right now it just seems sort of like a not-so-good border or dumbed-down border but we have this really cool second property that comes along with outline and that's called outline offset and this is what it makes it just amazing as far as I'm concerned so let's change this let's leave it red for now and I'll come down and add an outline offset and I'm going to do of five pixels and you can see that's pushed it away from my object by five pixels and let's just make that a little bit bigger so you can see it a bit bigger of a space that's a bit more obvious so I can move away from my object and one of the cool things with this is it's not actually going to push anything else around so if I had something over here this would actually overlap it's a little bit like drop shadow or my box shadow and things like that where it's going to cover stuff it won't actually increase the size of my container with the box model the same way that padding margin and border can do and also with that I can do a negative offset so if I put that is negative 20 it's going to go inside instead of outside so I can add sort of a border the stroke inside of my box which can be nice as well for a bit of a design element so instead of red maybe I'd make that white and it would give me this double border like that or if that was a positive so let's just bring this back to five pixels and give this the same color aquamarine as my box and then I sort of get this cool little double box thing going on that looks really nice so I really love the offset it's a nice little thing it gives us a bit mm you know a new way of expanding you have a border that's always stuck to it so I can break away one nice little use case that you can use this for is buttons so let's just make a quick button a href is equal to nothing class is equal to button hello closing so that should give me my link there it is and let's just style that button a little bit so my button will have a few things um let's do a text decoration of none to start with and let's give it a display:inline-block and a background background of steel blue padding of one m3m that looks all right color whoops color will be white and then a nice thing we can do so as I mentioned I bring in my offset so it's might not my offset my outline will do a nice little outline of say three pixels solid steel blue and it's just adding to the overall width of my button there so I have that and obviously when I hover on top right away it is give me a little flicker it's a little bit of a weird thing with the outline actually if you don't specify it in the hover it just doesn't exist it's usually the hover will copy everything you have automatically but it gets rid of the outline when I hover and we'll see in a second how that can do some interesting things but button:hover oops here and this is where it can get a little weird if I give this an offset now outline offset of say five pixels I you'll see it doesn't actually work it's kind of weird that way but if I come in here and I give this an outline of three pixels solid steel blue now it's going to jump out and away so I'm not sure why it works that way but I do need to specify my outline here and my align over here and the main reason I want to do that is because I actually want this to transition transition all ease-in out 300 milliseconds and it gives me this cool little hover effect going on right there where that little thing you know the whole box expands outwards and I like that and again if I didn't have this outline on there I would get this weird sort of disappearing outline maybe like that I find it really awkward and confusing so just for whatever reason you need to specify the outline in both places for it to actually work properly and if I don't have the outline here it sort of works but it's not really starting from any so it sort of just fades in maybe you like that I like having the outline in both of them so it just grows out and grows back in I find that looks a little bit more natural and of course say I made this white instead of and then did this with a negative offset you could do the same thing going inwards when you hover over your box sort of goes that way one thing that's really important with the negative offset is because the outline is on the outside so let's just make this red it's like a border it's going on the outside of my box and we'll make this red too so it's coming five pixels inside but it looks really small because it's doing five pixels inside but this is three so I'm left with only two there so if you really want a five pixel space all the way around I'd want to do eight so I'm going five plus three and now it's going where I'd sort of expected to switch those back to white just so we can make it look a little nicer and seeing it this this type of effect going on there for a nice little hover and that's the outline property so it's really not anything too complicated but again I didn't know about it for the longest time I don't see it used very often so I don't know if it's because people don't know about it or they just don't know in what cases to actually use it so I encourage you to check it out try it out if you do use it anywhere let me know share it in the comments below if you have any questions about how it works or any ideas for other videos just leave those down in the bottom in the comments if you like the video make sure you hit the thumbs up let me know that you liked it and I'll see you next Wednesday

Original Description

CSS outlines are awesome. They open up a world that simply isn't available with borders, and while you might not use them on all your sites, they can really come in handy. I start this video off looking at how to use it, and how it differs from the border property, and then how to make a fun little button using it. Want to play with the code? http://codepen.io/kevinpowell/pen/dNpBOJ --- Music by Chillhop: http://youtube.com/chillhopdotcom Joakim Karud - Canals: https://soundcloud.com/joakimkarud If you have your own channel, check out Chillhop for some awesome music.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Kevin Powell · Kevin Powell · 33 of 60

1 How to create an awesome navigation bar with HTML & CSS
How to create an awesome navigation bar with HTML & CSS
Kevin Powell
2 Improve your CSS by Keepin' it DRY
Improve your CSS by Keepin' it DRY
Kevin Powell
3 HTML & CSS for Beginners Part 6: Images
HTML & CSS for Beginners Part 6: Images
Kevin Powell
4 HTML & CSS for Beginners Part 7: File Structure
HTML & CSS for Beginners Part 7: File Structure
Kevin Powell
5 HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
HTML & CSS for Beginners Part 4: Bold and Italic text and HTML comments
Kevin Powell
6 HTML & CSS for Beginners Part 5: Links
HTML & CSS for Beginners Part 5: Links
Kevin Powell
7 HTML & CSS for Beginners Part 3: Paragraphs and Headings
HTML & CSS for Beginners Part 3: Paragraphs and Headings
Kevin Powell
8 HTML and CSS for Beginners Part 1: Introduction to HTML
HTML and CSS for Beginners Part 1: Introduction to HTML
Kevin Powell
9 HTML and CSS for Beginners Part 2: Building your first web page!
HTML and CSS for Beginners Part 2: Building your first web page!
Kevin Powell
10 HTML & CSS for Beginner Part 8: Introduction to CSS
HTML & CSS for Beginner Part 8: Introduction to CSS
Kevin Powell
11 HTML & CSS for Beginners Part 9: External CSS
HTML & CSS for Beginners Part 9: External CSS
Kevin Powell
12 HTML & CSS for Beginners Part 10: Divs & Spans
HTML & CSS for Beginners Part 10: Divs & Spans
Kevin Powell
13 HTML & CSS for Beginners Part 11: Classes & IDs
HTML & CSS for Beginners Part 11: Classes & IDs
Kevin Powell
14 HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
HTML & CSS for Beginners Part 12: The CSS Box Model - Margin, Borders & Padding explained
Kevin Powell
15 HTML & CSS for Beginners Part 13: Background Images
HTML & CSS for Beginners Part 13: Background Images
Kevin Powell
16 HTML & CSS for Beginners Part 14: Style Text with CSS
HTML & CSS for Beginners Part 14: Style Text with CSS
Kevin Powell
17 HTML & CSS for Beginners Part 15: How to style links
HTML & CSS for Beginners Part 15: How to style links
Kevin Powell
18 HTML & CSS for Beginners Part 16: CSS selectors and Specificity
HTML & CSS for Beginners Part 16: CSS selectors and Specificity
Kevin Powell
19 HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
HTML & CSS for Beginners Part 17: How to Create and Style HTML Lists
Kevin Powell
20 HTML & CSS for Beginners Part 18: How Floats and Clears work
HTML & CSS for Beginners Part 18: How Floats and Clears work
Kevin Powell
21 HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
HTML & CSS for Beginners Part 19: Colors with CSS - hex, rgba, and hsla
Kevin Powell
22 HTML & CSS for Beginners Part 20: How to center a div
HTML & CSS for Beginners Part 20: How to center a div
Kevin Powell
23 HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
HTML & CSS for Beginners Part 21: How to create a basic website layout - the HTML
Kevin Powell
24 HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
HTML & CSS for Beginners Part 22: How to create a basic layout - the CSS
Kevin Powell
25 How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
How to Create a Responsive Website from Scratch - Part 1: The HTML #Responsive #HTML5
Kevin Powell
26 How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
How to Create a Responsive Website from Scratch - Part 2: The Header and Hero area #Responsive #CSS3
Kevin Powell
27 How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
How to Create a Responsive Website from Scratch - Part 3: The About Section #Responsive #CSS
Kevin Powell
28 How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
How to Create a Responsive Website from Scratch - Part 4: Building a Responsive Portfolio Section
Kevin Powell
29 How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
How to Create a Responsive Website from Scratch - Part 5: Call To Action and Footer #CSS #Responsive
Kevin Powell
30 Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Tutorial: Learn how to use CSS Media Queries in less than 5 minutes
Kevin Powell
31 End of the year upate and what's coming to my channel to start the new year
End of the year upate and what's coming to my channel to start the new year
Kevin Powell
32 Create a CSS only Mega Dropdown Menu
Create a CSS only Mega Dropdown Menu
Kevin Powell
CSS Tutorial: Outline and Outline Offset
CSS Tutorial: Outline and Outline Offset
Kevin Powell
34 CSS Blending Modes
CSS Blending Modes
Kevin Powell
35 Parallax effect | 2 different ways to add it with jQuery
Parallax effect | 2 different ways to add it with jQuery
Kevin Powell
36 CSS Units: vh, vw, vmin, vmax #css #responsive #design
CSS Units: vh, vw, vmin, vmax #css #responsive #design
Kevin Powell
37 How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
How to Create a Website - Complete workflow | Part 01: Intro + Setting things up
Kevin Powell
38 100 Subscribers speed coding bonus video
100 Subscribers speed coding bonus video
Kevin Powell
39 How to Create a Website - Complete workflow | Part 02: The Markup #HTML
How to Create a Website - Complete workflow | Part 02: The Markup #HTML
Kevin Powell
40 How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
How to Create a Website - Complete workflow | Part 03: Sass Variables and a Mixin #Sass
Kevin Powell
41 How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
How to Create a Website - Complete workflow | Part 04: Setting up the hero and header
Kevin Powell
42 How to Create a Website - Complete workflow | Part 05: Typography & Buttons
How to Create a Website - Complete workflow | Part 05: Typography & Buttons
Kevin Powell
43 How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
How to Create a Website - Complete workflow | Part 06.1: Building the navigation with Flexbox
Kevin Powell
44 How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
How to Create a Website - Complete workflow | Part 06.2: Making the nav work with jQuery
Kevin Powell
45 Redesigning & Coding My Website #CreateICG
Redesigning & Coding My Website #CreateICG
Kevin Powell
46 How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
How to Create a Website - Complete workflow | Part 07: Starting the flexbox grid
Kevin Powell
47 How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
How to Create a Website - Complete workflow | Part 08: Promo & Problem shooting!
Kevin Powell
48 How to Create a Website - Complete workflow | Part 09: The CTA and Footer
How to Create a Website - Complete workflow | Part 09: The CTA and Footer
Kevin Powell
49 How to Create a Website - Complete workflow | Part 10: Making it responsive
How to Create a Website - Complete workflow | Part 10: Making it responsive
Kevin Powell
50 How to Create a Website - Complete workflow | Part 11: Making it responsive con't
How to Create a Website - Complete workflow | Part 11: Making it responsive con't
Kevin Powell
51 How to Create a Website - Complete workflow | Part 12: Putting the site online
How to Create a Website - Complete workflow | Part 12: Putting the site online
Kevin Powell
52 Create a Custom Grid System with CSS Calc() and Sass
Create a Custom Grid System with CSS Calc() and Sass
Kevin Powell
53 CSS em and rem explained #CSS #responsive
CSS em and rem explained #CSS #responsive
Kevin Powell
54 Should you use Bootstrap?
Should you use Bootstrap?
Kevin Powell
55 How to add Smooth Scrolling to your one page website with jQuery
How to add Smooth Scrolling to your one page website with jQuery
Kevin Powell
56 Let's learn Bootstrap 4
Let's learn Bootstrap 4
Kevin Powell
57 How I approach designing a website - my thought process
How I approach designing a website - my thought process
Kevin Powell
58 Build a website with Bootstrap 4 - Part 1: The setup
Build a website with Bootstrap 4 - Part 1: The setup
Kevin Powell
59 Build a website with Bootstrap 4 - Introduction
Build a website with Bootstrap 4 - Introduction
Kevin Powell
60 Build a website with Bootstrap 4 - Part 2:  Customizing Variables
Build a website with Bootstrap 4 - Part 2: Customizing Variables
Kevin Powell

Related Reads

📰
How I Built a Free Online Image & PDF Processing Platform with Vue 3 + FastAPI
Learn how to build a free online image and PDF processing platform using Vue 3 and FastAPI, and discover the benefits of combining these technologies for efficient file processing
Dev.to · IAMUU
📰
I Built a Free AI-Powered YouTube SEO Toolkit With Zero Budget. Here’s What Actually Happened.
Learn how a solo dev built a free AI-powered YouTube SEO toolkit with zero budget and the lessons they learned from the experience
Medium · Startup
📰
How to Create a Second Version of Yourself Inside Obsidian Using AI (Step-by-Step Guide)
Learn to create a second version of yourself inside Obsidian using AI with a step-by-step guide
Medium · ChatGPT
📰
How to prepare for Spain civil service TIC exam using AI in 2026
Learn how to prepare for the Spain civil service TIC exam using AI in 2026, boosting your chances of success with technology-driven study techniques
Dev.to · David García
Up next
I Asked Gemini to Build a Dashboard... I Didn't Expect This
Patech
Watch →