-
Hajipur, Bihar, 844101
A CSS Outline is a line drawn outside the element’s border to make it stand out.
It does not take up space and does not affect the layout.
element {
outline: 2px solid red;
}
2px
→ outline width
solid
→ outline style
red
→ outline color
Feature | Border | Outline |
---|---|---|
Affects Layout | Yes | No |
Can be Rounded | Yes (border-radius ) |
No |
Position | Inside element box | Outside border |
outline-style
: Type of outline
outline-color
: Color of the outline
outline-width
: Thickness of the outline
outline-offset
: Space between border and outline
outline
: Shorthand for width, style, color
button {
outline-style: dotted;
outline-color: green;
outline-width: 3px;
outline-offset: 5px;
}
input {
outline: 2px dashed blue;
}
Moves the outline away from the element border.
div {
outline: 2px solid black;
outline-offset: 10px;
}
Q1. Add a 3px solid black outline to a <div>
.
Q2. Apply a dotted green outline to all <p>
tags.
Q3. Set only the outline color of a button to blue.
Q4. Set a dashed outline of 2px to all input fields.
Q5. Create a rule using shorthand to set a red 4px double outline.
Q6. Add 10px space between the border and outline using outline-offset
.
Q7. Write a class .highlight
that gives a yellow solid outline.
Q8. Apply a groove-style outline to a section element.
Q9. Create a hover effect that adds a 2px solid outline to a card.
Q10. Set outline-width
, outline-style
, and outline-color
individually on a heading.
Q1: What does the CSS outline property do?
Q2: Which of the following outlines takes up space in the layout?
Q3: Which property moves the outline away from the element?
Q4: Which of these is a valid outline style?
Q5: What is the correct shorthand syntax for outline?
Q6: Which property does NOT exist for outlines?
Q7: Which outline style creates a dotted line?
Q8: How to add an outline only when an element is focused?
Q9: Which is true about outlines?
Q10: Which of these will add a 2px red dashed outline to an element?