Front-end Tutorials

Front-end Tutorials

HTMLCSSSassJavaScriptReactJS
CMS Tutorials

CMS Tutorials

WordPress
Tutorials expand

CSS Properties

CSS hanging-punctuation Property

Posted in CSS Tutorial
Updated on Oct 03, 2024
By Mari Selvan
👁️ 16 - Views
⏳ 4 mins
💬 1 Comment
CSS hanging-punctuation Property

Photo Credit to CodeToFun

🙋 Introduction

The hanging-punctuation property in CSS allows you to control the positioning of punctuation marks in relation to the surrounding text.

This property is particularly useful for creating typographic effects, such as when you want punctuation marks to hang outside of the main text block for a cleaner, more visually appealing layout.

💡 Syntax

The syntax for the hanging-punctuation property is as follows:

Syntax
Copied
Copy To Clipboard
element {
  hanging-punctuation: value;
}

The value can be one of the following:

  • none
  • first
  • last
  • first last
  • allow-end
  • allow-start

🎛️ Default Value

The default value of the hanging-punctuation property is none, which means that no special hanging behavior is applied to punctuation marks.

🏠 Property Values

ValueDescription
noneNo hanging punctuation is applied. Punctuation marks are positioned normally within the text block.
firstThe punctuation mark at the beginning of a line hangs outside the block.
lastThe punctuation mark at the end of a line hangs outside the block.
first lastBoth the punctuation mark at the beginning and the end of a line hang outside the block.
allow-endAllows the punctuation mark at the end of a line to hang outside the block if it would improve the visual alignment.
allow-startAllows the punctuation mark at the beginning of a line to hang outside the block if it would improve the visual alignment.

📄 Example

In this example, we will use the hanging-punctuation property to make the punctuation mark at the end of a line hang outside the text block.

index.html
Copied
Copy To Clipboard
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CSS hanging-punctuation Example</title>
  <style>
    p {
      hanging-punctuation: last;
    }
  </style>
</head>
<body>
  <h1>Paragraph with Hanging Punctuation</h1>
  <p>
    This is an example paragraph with hanging punctuation. Notice how the punctuation mark at the end of the line hangs outside the text block.
  </p>
</body>
</html>

🖥️ Browser Compatibility

The hanging-punctuation property is supported in modern browsers, including the latest versions of Chrome, Firefox, and Safari. It may not be fully supported in older versions of browsers or some specific browser implementations, so it's a good idea to test across different browsers to ensure the desired effect.

🎉 Conclusion

The hanging-punctuation property offers a useful way to enhance typographic aesthetics by controlling the placement of punctuation marks.

By experimenting with different values, you can achieve a variety of visual effects that contribute to a more polished and professional look for your text content. Utilize this property to improve the readability and visual appeal of your web typography.

👨‍💻 Join our Community:

To get interesting news and instant updates on Front-End, Back-End, CMS and other Frameworks. Please Join the Telegram Channel:

Author

author
👋 Hey, I'm Mari Selvan

For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.

Buy me a coffee to make codetofun.com free for everyone.

Buy me a Coffee

Share Your Findings to All

Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
We make use of cookies to improve our user experience. By using this website, you agree with our Cookies Policy
AgreeCookie Policy