hanging-punctuation
Definition
The hanging-punctuation CSS property is used to control whether punctuation marks at the beginning or end of a line are allowed to hang outside the text box or not. When this property is enabled, the punctuation marks that would normally appear at the beginning or end of a line are shifted outside the text box, which can create a cleaner and more visually appealing layout.
Examples
Enable hanging punctuation for all paragraphs:
p {
hanging-punctuation: first;
}
Enable hanging punctuation for specific elements:
blockquote {
hanging-punctuation: last;
}
h1 {
hanging-punctuation: end;
}
Disable hanging punctuation:
p {
hanging-punctuation: none;
}
Values
Value | Description |
---|---|
none | Punctuation marks are not allowed to hang outside the text box. |
first | Punctuation marks at the beginning of a line are allowed to hang outside the text box. |
last | Punctuation marks at the end of a line are allowed to hang outside the text box. |
end | Punctuation marks at the end of the last line in a block container are allowed to hang outside the text box. |
allow-end | Punctuation marks at the end of the last line in a block container are allowed to hang outside the text box only if the container's writing mode is horizontal. |
Best Practices
- Use hanging punctuation sparingly and only when it improves the visual design of your content.
- Avoid using hanging punctuation for large blocks of text, as it can make the text harder to read.
- Test your design across different screen sizes and devices to ensure that the hanging punctuation doesn't cause layout issues or readability problems.
- Consider using fallback options for browsers that don't support the hanging-punctuation property, such as manually adding hanging punctuation marks with the ::before and ::after pseudo-elements.
- Don't rely solely on hanging punctuation to create visually appealing content; it should be used in conjunction with other design elements to create a cohesive layout.
Browser Compatibility
Chrome | Firefox | Safari | Internet Explorer | Microsoft Edge | Opera | Opera Mini |
---|---|---|---|---|---|---|
Yes | Yes | Yes | No | Yes | Yes | No |