{"id":656,"date":"2024-01-25T17:02:29","date_gmt":"2024-01-25T23:02:29","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=656"},"modified":"2024-01-25T17:21:16","modified_gmt":"2024-01-25T23:21:16","slug":"fading-out-text-with-mask","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/fading-out-text-with-mask\/","title":{"rendered":"Fading Out Text with Mask"},"content":{"rendered":"\n<p>If you&#8217;re going to fade out some text, I&#8217;m gonna call it and say the best way, while also being the easiest, is using a <code>mask<\/code>. <a href=\"https:\/\/polypane.app\/blog\/my-take-on-fading-content-using-transparent-gradients-in-css\/\">Kilian Valkhof covered this recently<\/a>, rejecting the idea of an overlay gradient, and also offering the idea of using <code>background-clip<\/code>. But <code>mask<\/code> is the clear winner. Let&#8217;s get that sucker un-prefixed already!<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.fade-out-text<\/span> {\n  <span class=\"hljs-attribute\">-webkit-mask-image<\/span>: <span class=\"hljs-built_in\">linear-gradient<\/span>(to bottom, white, transparent);\n  <span class=\"hljs-attribute\">mask-image<\/span>: <span class=\"hljs-built_in\">linear-gradient<\/span>(to bottom, white, transparent);\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<!--more-->\n\n\n\n<p>The gradient technique is such a classic though. I remember <a href=\"https:\/\/css-tricks.com\/examples\/ReadMoreFade\/\">playing with that<\/a> over a decade ago. Here&#8217;s a proper demo of masking though:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_yLwzZBG\" src=\"\/\/codepen.io\/anon\/embed\/yLwzZBG?height=450&amp;theme-id=47434&amp;slug-hash=yLwzZBG&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed yLwzZBG\" title=\"CodePen Embed yLwzZBG\" class=\"cp_embed_iframe\" style=\"width:100%;overflow:hidden\">CodePen Embed Fallback<\/iframe><\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re going to fade out some text, I&#8217;m gonna call it and say the best way, while also being the easiest, is using a mask. Kilian Valkhof covered this recently, rejecting the idea of an overlay gradient, and also offering the idea of using background-clip. But mask is the clear winner. Let&#8217;s get that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":659,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[7,89],"class_list":["post-656","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-css","tag-mask"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2024\/01\/fade-thumb.jpg?fit=1000%2C500&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=656"}],"version-history":[{"count":5,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/656\/revisions"}],"predecessor-version":[{"id":662,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/656\/revisions\/662"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/659"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}