{"id":1501,"date":"2021-10-08T19:38:28","date_gmt":"2021-10-08T19:38:28","guid":{"rendered":"https:\/\/www.antpace.com\/blog\/?p=1501"},"modified":"2025-08-25T17:53:28","modified_gmt":"2025-08-25T17:53:28","slug":"css-for-weighted-hyperlink-decoration","status":"publish","type":"post","link":"https:\/\/www.antpace.com\/blog\/css-for-weighted-hyperlink-decoration\/","title":{"rendered":"CSS for Weighted Hyperlink Decoration"},"content":{"rendered":"<p>How to add an underline to website text should be covered in any intro to web development course. The old-fashioned HTML way uses a now-deprecated\u00a0tag:<\/p>\n<pre>&lt;u&gt;This will appear underlined!&lt;\/u&gt;<\/pre>\n<p>Modern approaches use CSS to define such a style:<\/p>\n<pre>&lt;p style=\"text-decoration: underline;\"&gt;This will appear underlined!&lt;\/p&gt;<\/pre>\n<p>Even better, properly written code will separate the inline styles, like so:<\/p>\n<pre>&lt;style&gt;\n.underlined-text{\n  text-decoration: underline;\n}\n&lt;\/style&gt;\n&lt;p class=\"underlined-text\"&gt;This will appear underlined!&lt;\/p&gt;<\/pre>\n<p>For hyperlink text, I might want to hide the underline when a user mouses over it. That&#8217;s easy with the &#8220;hover&#8221; <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Pseudo-classes\" target=\"_blank\" rel=\"noopener\">pseudo-class<\/a>:<\/p>\n<pre>&lt;style&gt;\na.hyperlink-text{\n  text-decoration: underline;\n}\na.hyperlink-text:hover{\n  text-decoration: none;\n}\n&lt;\/style&gt;\n&lt;a class=\"hyperlink-text\"&gt;This will appear underlined!&lt;\/a&gt;\n<\/pre>\n<p>But, suppose I want to have that underline to become thicker instead of disappearing. That will require an <strong>advanced, super-secret<\/strong> CSS technique. To make it work, we will utilize <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/box-shadow\" target=\"_blank\" rel=\"noopener\"><em>box-shadow<\/em><\/a>.<\/p>\n<p>In the world of cascading style sheets, the box-shadow property adds a shadow effect around any HTML element. The shadow is described by its offsets, relative to the element. Leveraging this, we can create a shadow that looks like an underline. On hover, we can adjust the settings to change its appearance:<\/p>\n<pre>&lt;style&gt;\na.hyperlink-text{\n  text-decoration: none;\n  box-shadow: inset 0 -1px 0 rgb(15 15 15);\n}\na.hyperlink-text:hover{\n  -webkit-box-shadow: inset 0 0 0 rgb(0 0 0 \/ 0%), 0 3px 0 rgb(0 0 0);\n  box-shadow: inset 0 0 0 rgb(0 0 0 \/ 0%), 0 3px 0 rgb(0 0 0);\n}\n&lt;\/style&gt;\n&lt;a class=\"hyperlink-text\"&gt;This will appear underlined!&lt;\/a&gt;\n<\/pre>\n<p>Point your cursor over any of the hyperlinks in this post to see what it looks like. Experiment with the above code to make it your own.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to add an underline to website text should be covered in any intro to web development course. The old-fashioned HTML way uses a now-deprecated\u00a0tag: &lt;u&gt;This will appear underlined!&lt;\/u&gt; Modern approaches use CSS to define such a style: &lt;p style=&#8221;text-decoration: underline;&#8221;&gt;This will appear underlined!&lt;\/p&gt; Even better, properly written code will separate the inline styles, like &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.antpace.com\/blog\/css-for-weighted-hyperlink-decoration\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;CSS for Weighted Hyperlink Decoration&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":3231,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5],"tags":[33,66,140],"class_list":["post-1501","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-design","category-web-development","tag-css","tag-html","tag-web-development"],"_links":{"self":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/1501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/comments?post=1501"}],"version-history":[{"count":1,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/1501\/revisions"}],"predecessor-version":[{"id":3232,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/posts\/1501\/revisions\/3232"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media\/3231"}],"wp:attachment":[{"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/media?parent=1501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/categories?post=1501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antpace.com\/blog\/wp-json\/wp\/v2\/tags?post=1501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}