{"id":2503,"date":"2021-07-20T11:03:52","date_gmt":"2021-07-20T11:03:52","guid":{"rendered":"https:\/\/learncode.tinjurewp.com\/?p=2503"},"modified":"2021-07-21T11:12:15","modified_gmt":"2021-07-21T11:12:15","slug":"styling-link-underline","status":"publish","type":"post","link":"https:\/\/learncode.tinjurewp.com\/styling-link-underline\/","title":{"rendered":"Styling Links Underline"},"content":{"rendered":"<p>Whenever I start developing a new website or work on a new theme, I happen to spend quite some time <em>how to underline<\/em> hypertext. Recently, I while I was working on a new block-based theme, I happened to reach into the same pigeonhole again. This was time to bookmark my references for use cases.<\/p>\n<p>In <a href=\"https:\/\/css-tricks.com\/styling-links-with-real-underlines\/\" target=\"_blank\" rel=\"noopener\">this CSS-Tricks article<\/a>, Ollie Williams writes &#8220;<em>hyperlinks are the defining feature of the internet; and from the internet\u2019s inception, they have been underlined. It\u2019s a universally understood convention. The meaning is crystal clear \u2014 an underline means a link<\/em>&#8220;.<\/p>\n<p>Ollie reminds us that many websites have ditched the classic default underlining of hyperlinks including <em>The New York Times<\/em>, <em>New York<\/em> <em>Magazine<\/em>, <em>The Washington Post<\/em>, Bloomberg, Amazon, Apple, GitHub, Twitter, Wikipedia.<!--more--><\/p>\n<p>It appears that it&#8217;s not only me but others too face similar confusion while styling links underlines. Here Chris from CSS-Tricks writes:<\/p>\n<blockquote><p><em class=\"explanation\">Styling the underlines that sit beneath links can be a tricky business, and I constantly forget what\u2019s the best approach depending on the situation. <cite>Chris Coyier | <a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/\" target=\"_blank\" rel=\"noopener\">CSS-Tricks<\/a><br \/>\n<\/cite><\/em><\/p><\/blockquote>\n<p>However I am from an ol&#8217;school and prefer underline in my posts. I often underline text with <code>border-bottom<\/code> and occasionally with <code>box-shadow<\/code> and try to avoid <code>text-decoration<\/code>, often without fully understanding their pros and cons.<\/p>\n<p>In this <a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/\" target=\"_blank\" rel=\"noopener\">CSS-Tricks article<\/a>, <em>John Jameson<\/em> describes beautifully common ways to underline links with good and bad for each.<\/p>\n<h5><strong><code>text-decoration<\/code><\/strong><\/h5>\n<p>This is the default and most common way to style hyperlinks. It has just an single property.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-css\">\/* text-decoration *\/\na {\n  text-decoration: underline;\n}<\/code><\/pre>\n<p>One of the main disadvantage of <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/text-decoration\" target=\"_blank\" rel=\"noopener\"><code>text-decoration<\/code><\/a> is color customization, which uses the default color unless some hacks like in the <a href=\"https:\/\/css-tricks.com\/styling-links-with-real-underlines\/\" target=\"_blank\" rel=\"noopener\">following from Olli&#8217;s post<\/a>:<\/p>\n<pre class=\"line-numbers\"><code class=\"language-css\">a {\n  text-decoration-color: #EA215A;\n  text-decoration-thickness: .125em;\n  text-underline-offset: 1.5px;\n}<\/code><\/pre>\n<h5><strong><code>border-bottom<\/code><\/strong><\/h5>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/border-bottom\" target=\"_blank\" rel=\"noopener\"><code>border-bottom<\/code><\/a> property is common alternative to <code>text-decoration<\/code>, to style links with <em>color<\/em>, <em>thickness<\/em> and other styling. Revisiting the above example again.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-css\">\/* styling with border-bottom *\/\na {\n  text-decoration: none;\n  border-bottom: 1px solid #EA215A;\n}<\/code><\/pre>\n<p>Underlining with border-bottom property is <em>below<\/em> the <em>descenders<\/em> which <a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/#border-bottom\" target=\"_blank\" rel=\"noopener\">can be addressed<\/a> by making elements <code>inline-block<\/code> and reducing <code>line-height<\/code>.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-css\">\/* border-bottom *\/\n.a {\n  text-decoration: none;\n  border-bottom: 1px solid #EA215A;\n  display: inline-block;\n  line-height: 0.85;\n}<\/code><\/pre>\n<p>One of the main disadvantages of this simple method is <a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/#border-bottom\" target=\"_blank\" rel=\"noopener\">it is positioned far away and difficult to reposition<\/a>.<\/p>\n<h5><strong><code>box-shadow<\/code><\/strong><\/h5>\n<p><a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/#box-shadow\" target=\"_blank\" rel=\"noopener\">This method<\/a> &#8216;<em>draws an underline with two inset box shadows: one to create a rectangle and a second to cover it up<\/em>&#8216;.<\/p>\n<pre class=\"line-numbers\"><code class=\"language-css\">\/* box-shadow *\/\n.a {\n  background-size: 1px 1em;\n  box-shadow: \n    inset 0 -0.175em white,\n    inset 0 -0.2em #000;\n  display: inline;\n}<\/code><\/pre>\n<p>John Jameson describes also describes styling links with <a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/#background-image\" target=\"_blank\" rel=\"noopener\">background-image<\/a> and <a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/#svg-filters\" target=\"_blank\" rel=\"noopener\">svg filters<\/a>. Additional description on <code>box-shadow<\/code> property is available in <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/box-shadow\" target=\"_blank\" rel=\"noopener\">this MDN documentation<\/a>.<\/p>\n<p>To wrap up, <code>border-bottom<\/code> and <code>box-shadow<\/code> are two common styling methods that are applied in my own themes and also in WordPress default themes.<\/p>\n<h6>Some Useful Resources<\/h6>\n<ul>\n<li><a href=\"https:\/\/css-tricks.com\/styling-underlines-web\/\" target=\"_blank\" rel=\"noopener\">Styling Underlines on the Web<\/a> | CSS-Tricks<\/li>\n<li><a href=\"https:\/\/benjam.info\/blog\/posts\/2015-01-31-css-underline\/\" target=\"_blank\" rel=\"noopener\">CSS Underlines Suck<\/a> | B. Woodruff<\/li>\n<li><a href=\"https:\/\/sharkcoder.com\/visual\/underline\" target=\"_blank\" rel=\"noopener\">CSS Underline: 20+ Examples<\/a> | Shark Coder<\/li>\n<li><a href=\"https:\/\/css-tricks.com\/styling-links-with-real-underlines\/\" target=\"_blank\" rel=\"noopener\">Styling Links with Real Underlines<\/a> | CSS-Tricks<\/li>\n<li><a href=\"https:\/\/walterebert.com\/blog\/underlined-links-css3-box-shadow-text-shadow\/\" target=\"_blank\" rel=\"noopener\">Create better looking underlined links with CSS3 box-shadow and text-shadow<\/a> | Walter Ebert<\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/box-shadow\" target=\"_blank\" rel=\"noopener\">Box-shadow<\/a> and <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Background_and_Borders\/Box-shadow_generator\" target=\"_blank\" rel=\"noopener\">Box-shadow generator<\/a> | MDN Web Doc<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Whenever I start developing a new website or work on a new theme, I happen to spend quite some time how to underline hypertext. Recently, I while I was working on a new block-based theme, I happened to reach into the same pigeonhole again. This was time to bookmark my references for use cases. In [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[20],"tags":[],"class_list":["post-2503","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/2503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/comments?post=2503"}],"version-history":[{"count":0,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/posts\/2503\/revisions"}],"wp:attachment":[{"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/media?parent=2503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/categories?post=2503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learncode.tinjurewp.com\/wp-json\/wp\/v2\/tags?post=2503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}