<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Håvard Brynjulfsen</title>
    <description>The latest articles on DEV Community by Håvard Brynjulfsen (@havardob).</description>
    <link>https://dev.to/havardob</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F200715%2Ff51c8d39-ab39-4ba9-83de-fbccaf799616.jpg</url>
      <title>DEV Community: Håvard Brynjulfsen</title>
      <link>https://dev.to/havardob</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/havardob"/>
    <language>en</language>
    <item>
      <title>Simple progressive enhancements in CSS</title>
      <dc:creator>Håvard Brynjulfsen</dc:creator>
      <pubDate>Sun, 15 Dec 2024 15:28:13 +0000</pubDate>
      <link>https://dev.to/havardob/simple-progressive-enhancements-in-css-44p3</link>
      <guid>https://dev.to/havardob/simple-progressive-enhancements-in-css-44p3</guid>
      <description>&lt;p&gt;CSS has changed a lot in the last couple of years. It feels like we're getting new features monthly now. New features are well and all, but it's hard to keep up with what's fully supported or safe to use.&lt;/p&gt;

&lt;p&gt;Enter &lt;em&gt;progressive enhancements&lt;/em&gt;: code features and syntax that provides you with safe fallbacks in case your users visits your website in a browser that lacks support.&lt;/p&gt;

&lt;p&gt;Here are a few simple CSS properties and techniques that are safe to use; enhancing the experience for some users, but provides satisfying fallbacks for others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Better text with &lt;code&gt;text-wrap: pretty&lt;/code&gt; and &lt;code&gt;text-wrap: balance&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Not all browsers support the &lt;code&gt;text-wrap&lt;/code&gt; values &lt;code&gt;balance&lt;/code&gt; and &lt;code&gt;pretty&lt;/code&gt;, but they are &lt;strong&gt;safe&lt;/strong&gt; to use.&lt;/p&gt;

&lt;p&gt;If you're not familiar with these values they are ways to "fix" your text to look (you've guessed it) prettier or more balanced.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pretty&lt;/code&gt; fixes the problem with "orphan" words, when the last word of a paragraph of text wraps to a new line, leaving it all alone at the bottom. &lt;code&gt;pretty&lt;/code&gt; ensures that the last word gets accompanied by another, which is great for &lt;strong&gt;headings&lt;/strong&gt; (NOTE: Don't use it for larger portions of body text, as it uses a slower algorithm to calculate the best outcome).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap#pretty" rel="noopener noreferrer"&gt;MDN documentation for text-wrap: pretty&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;balance&lt;/code&gt; adjusts your paragraphs so that the text is wrapped in a way that balances the number of characters on each line, enhancing layout quality and legibility. It's useful for &lt;strong&gt;paragraphs&lt;/strong&gt; of a certain length, e.g. leading text or some marketing copy inside a banner. (NOTE: Do not use this on all &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt; tags in your body text. The calculating of the perfect balance based on the number of characters is computationally expensive, so the browsers have a cap on this feature based on lines of text: six or less for Chromium, and ten or less for Firefox)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/text-wrap#balance" rel="noopener noreferrer"&gt;MDN documentation for text-wrap: balance&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Demo
&lt;/h3&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/havardob/embed/mybOxgp?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  The fallback
&lt;/h3&gt;

&lt;p&gt;The only thing that happens if the browser doesn't support these features is that the text will have orphans or might not be as balanced as you'd prefer. And that's OK; we've lived with this for 30+ years of web browsing, so it's not harming the experience of users with not-supported browsers.&lt;/p&gt;




&lt;h2&gt;
  
  
  Auto-growing form fields with &lt;code&gt;field-sizing: content&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Ever been frustrated that &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;s doesn't automatically grow when you write in them? Well, that's finally being fixed, with &lt;code&gt;field-sizing: content&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This property and value will make your &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt; automatically grow based on its content. I recommend you use it for &lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt; especially, and it is safe to use today, even though it's marked "experimental" by MDN.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/field-sizing" rel="noopener noreferrer"&gt;MDN documentation for field-sizing&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Demo
&lt;/h3&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/havardob/embed/GgKNxVx?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  The fallback
&lt;/h3&gt;

&lt;p&gt;The fallback for this is simple: the fields won't grow if a browser doesn't support the feature. And that's OK, too!&lt;/p&gt;




&lt;h2&gt;
  
  
  The psuedo elements &lt;code&gt;::marker&lt;/code&gt; and &lt;code&gt;::placeholder&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Want to style the disc indicators on list items in an &lt;code&gt;&amp;lt;ul&amp;gt;&lt;/code&gt;, change the colors of the numbers in an &lt;code&gt;&amp;lt;ol&amp;gt;&lt;/code&gt;, or style the placeholder of an &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt;? You can, using psuedo selectors like &lt;code&gt;::marker&lt;/code&gt; and &lt;code&gt;::placeholder&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Note that the &lt;code&gt;::marker&lt;/code&gt; element is a weird one, as there's only a handful of properties that will work with this selector:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  All &lt;code&gt;font&lt;/code&gt; properties&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;white-space&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;color&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  &lt;code&gt;text-combine-upright&lt;/code&gt;, &lt;code&gt;unicode-bidi&lt;/code&gt;, and &lt;code&gt;direction&lt;/code&gt; properties&lt;/li&gt;
&lt;li&gt;  The &lt;code&gt;content&lt;/code&gt; property&lt;/li&gt;
&lt;li&gt;  All &lt;code&gt;animation&lt;/code&gt; and &lt;code&gt;transition&lt;/code&gt; properties&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Read more about it here: &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::marker" rel="noopener noreferrer"&gt;MDN documentation for ::marker&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For &lt;code&gt;::placeholder&lt;/code&gt; you can do pretty much anything you can do with normal text, change the &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;font-weight&lt;/code&gt;, &lt;code&gt;font-family&lt;/code&gt; etc., but please keep in mind that the placeholder of an input still should &lt;em&gt;look like&lt;/em&gt; a placeholder, not look like there's already a value typed into the input.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/::placeholder" rel="noopener noreferrer"&gt;MDN documentation for ::placeholder&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Demo
&lt;/h3&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/havardob/embed/RNboOqq?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  The fallback
&lt;/h3&gt;

&lt;p&gt;These doesn't work in every browser or browser versions, but using them won't ruin anything either, making it a perfect progressive enhancement. Markers like discs and numbers will fallback to have the same color as the list item's text, while the placeholder will have the browser's built-in style.&lt;/p&gt;




&lt;h2&gt;
  
  
  In conclusion
&lt;/h2&gt;

&lt;p&gt;It's hard to keep up with what's safe to use in CSS, as &lt;a href="https://webstatus.dev/" rel="noopener noreferrer"&gt;Baseline (from webstatus.dev)&lt;/a&gt; and &lt;a href="https://caniuse.com/" rel="noopener noreferrer"&gt;caniuse.com&lt;/a&gt; only states if something is available in a certain browser version, not what will happen to your UI if the selector, property or value isn't supported.&lt;/p&gt;

&lt;p&gt;Always figure out what fallbacks the experimental or less-supported functionality will yield.&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
