<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pedro Lopes, Author at Blog IT</title>
	<atom:link href="https://blogit.create.pt/author/pedrolopes/feed/" rel="self" type="application/rss+xml" />
	<link>https://blogit.create.pt/author/pedrolopes/</link>
	<description>Create IT blogger community</description>
	<lastBuildDate>Wed, 25 May 2022 14:58:52 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>The future of dynamic color palettes in CSS</title>
		<link>https://blogit.create.pt/pedrolopes/2022/05/25/the-future-of-dynamic-color-palettes-in-css/</link>
					<comments>https://blogit.create.pt/pedrolopes/2022/05/25/the-future-of-dynamic-color-palettes-in-css/#respond</comments>
		
		<dc:creator><![CDATA[Pedro Lopes]]></dc:creator>
		<pubDate>Wed, 25 May 2022 14:58:49 +0000</pubDate>
				<category><![CDATA[Web Development]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12707</guid>

					<description><![CDATA[<p>When you have a theme based on a color picked by your users, it can be hard to find intermediate values for things like hover and active states, or even colors that look or contrast well together. There are currently some convoluted ways of doing this, using CSS filters to change brightness or contrast, or [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2022/05/25/the-future-of-dynamic-color-palettes-in-css/">The future of dynamic color palettes in CSS</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When you have a theme based on a color picked by your users, it can be hard to find intermediate values for things like hover and active states, or even colors that look or contrast well together.</p>



<p>There are currently some convoluted ways of doing this, using <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/filter">CSS filters</a> to change brightness or contrast, or <a href="https://developer.epages.com/blog/coding/css-can-do-that-color-manipulation-for-the-fearless/">using CSS variables to separate each of the color’s values and use the calc function to manipulate them</a>.</p>



<p>With the <a href="https://www.w3.org/TR/css-color-5">CSS Color Module Level 5</a>, there are some great new features that will make this manipulation much easier to achieve.</p>



<p>Keep in mind, these features are not yet widely supported by browsers, being either experimental or hidden behind flags. Hopefully, these will start to roll out during this year.</p>



<h2 class="wp-block-heading">Color spaces</h2>



<p>Before getting into color manipulation, one other feature that will improve the results of dynamic color palettes are <strong>color spaces</strong>.</p>



<p>Color spaces essentially determine how colors are defined and how they can be represented. The <a href="https://www.w3.org/TR/css-color-4/">CSS Color 4</a> introduces a bunch of ways to define colors, one of them being <strong>Lightness Chroma Hue</strong> (LCH). LCH introduces many improvements over RGB, such as more colors and more uniformity. For more detail on this, I recommend Lea Verou’s blog post <a href="https://lea.verou.me/2020/04/lch-colors-in-css-what-why-and-how/">“LCH colors in CSS: what, why, and how?”</a>.</p>



<h2 class="wp-block-heading">Color mix</h2>



<p>The <code>color-mix</code> function lets us mix two colors with a given weight to each. You can mix the theme color with white or black to make it lighter or darker, or mix it with the secondary color to get interpolated values between them.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: css; title: ; notranslate">
color: color-mix(in srgb, var(--primary-color) 70%, white);
color: color-mix(in srgb, var(--primary-color) 70%, black);
color: color-mix(in lch, var(--primary-color), var(--secondary-color));
</pre></div>


<p><strong>Resources:</strong></p>



<ul class="wp-block-list"><li><a href="https://www.w3.org/TR/css-color-5/#color-mix">CSS Color 5 &#8211; color-mix</a></li><li><a href="https://caniuse.com/mdn-css_types_color_color-mix">Can I Use &#8211; color-mix</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-mix">MDN &#8211; color-mix</a></li></ul>



<h2 class="wp-block-heading">Relative colors</h2>



<p>With relative colors, you can define color values based on a given color, and change the individual values that make up that given color. Remember the approach I mentioned above that separates each of the color’s components into a CSS variable? This <a href="https://blog.jim-nielsen.com/2021/css-relative-colors/">blog post by Jim Nielsen</a> compares the two approaches.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
// Reduce the primary color transparency
color: rgb(from var(--primary-color) r g b / 80%);

// Reduce the lightness using the LCH color space
color: lch(from var(--primary-color) calc(l / 2) c h);
</pre></div>


<p><strong>Resources:</strong></p>



<ul class="wp-block-list"><li><a href="https://www.w3.org/TR/css-color-5/#relative-colors">CSS Color 5 &#8211; relative colors</a></li></ul>



<h2 class="wp-block-heading">Color contrast</h2>



<p>With the <code>color-contrast</code> function, we can let the browser automatically determine a color that contrasts with a given color and matches accessibility requirements.</p>



<p>At its simplest, the function receives a color value (typically the background color) and returns either white or black, depending on which has better contrast.</p>



<p>If you want custom contrast colors instead of black or white, you can provide a list of colors to pick from (using the <code>vs</code> keyword), and the color with the highest contrast will be chosen. As a backup, you can define a contrast target (using the <code>to</code> keyword) and if no color matches that contrast, white or black will be picked. The contrast target can be given as a number or as a level from WCAG (AA, AA-large, AAA, and AAA-large).</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
// Chooses black or white based on which has better contrast
color: color-contrast(var(--bg-color));

// Chooses a contrasting color from a given list (after the &quot;vs&quot;), that result in  a contrast level of at least AA. If none match, picks white or black
color: color-contrast(
	var(--bg-color)
	vs
	var(--text-color),
	var(--text-color--light),
	var(--text-color--lightest),
	to AA
);
</pre></div>


<p><strong>Resources:</strong></p>



<ul class="wp-block-list"><li><a href="https://www.w3.org/TR/css-color-5/#colorcontrast">CSS Color 5 &#8211; color-contrast</a></li><li><a href="https://caniuse.com/mdn-css_types_color_color-contrast">Can I Use &#8211; color-contrast</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/color-contrast">MDN &#8211; color-contrast</a></li></ul>



<h2 class="wp-block-heading">Conclusion</h2>



<p>The future is looking bright for dynamic color themes in CSS. We will soon be able to move away from convoluted hacks and start using native functions.</p>



<p>Do you find these color features useful? How do you get around this currently? Do you know of any other features that you think help with this topic? Leave a comment or reach out to me on Twitter <a href="https://twitter.com/pedronavelopes" target="_blank" rel="noreferrer noopener">@pedronavelopes</a>.</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2022/05/25/the-future-of-dynamic-color-palettes-in-css/">The future of dynamic color palettes in CSS</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/pedrolopes/2022/05/25/the-future-of-dynamic-color-palettes-in-css/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Handling not found routes in Angular</title>
		<link>https://blogit.create.pt/pedrolopes/2022/05/05/handling-not-found-routes-in-angular/</link>
					<comments>https://blogit.create.pt/pedrolopes/2022/05/05/handling-not-found-routes-in-angular/#respond</comments>
		
		<dc:creator><![CDATA[Pedro Lopes]]></dc:creator>
		<pubDate>Thu, 05 May 2022 11:31:15 +0000</pubDate>
				<category><![CDATA[Angular]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[404]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12669</guid>

					<description><![CDATA[<p>In this post, we will see how we can handle 404 routes using a not found component in an Angular. There are two types of 404 routes that we want to handle. Static 404 &#8211; the URL the user navigates to doesn&#8217;t match any route Dynamic 404 &#8211; the URL matches a route, but the [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2022/05/05/handling-not-found-routes-in-angular/">Handling not found routes in Angular</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>In this post, we will see how we can handle 404 routes using a not found component in an Angular.</p>



<p>There are two types of 404 routes that we want to handle.</p>



<ul class="wp-block-list"><li><strong>Static 404</strong> &#8211; the URL the user navigates to doesn&#8217;t match any route</li><li><strong>Dynamic 404</strong> &#8211; the URL matches a route, but the data associated with that route does not exist. For example, you navigate to a detail page with an ID, but no item exists with that ID.</li></ul>



<p>For this post, I assume that there is a component named <code>NotFoundComponent</code> that is the not found page to show the user. Replace this with whatever component</p>



<h2 class="wp-block-heading">Static 404 routes</h2>



<p>To set up a static 404 page, you need to add two routes to your <code>RoutingModule</code> configuration.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
const routes: Routes = &#x5B;
    // Other routes
    { path: &#039;404&#039;, component: NotFoundComponent },
    { path: &#039;**&#039;, component: NotFoundComponent }
]
</pre></div>


<p>We used a catchall route <code><em>'</em>**'</code> that matches whatever route didn&#8217;t match above, and shows our not found page.</p>



<p>Make sure to keep the catchall route at the end of your routes, otherwise the routes below it will not be accessible.</p>



<p>Another option here would&#8217;ve been to redirect the user to the <code>'404'</code> route, but that way you lose the context of the URL. If the user navigates back, he would go to the non-existing route and be redirected to the <code>'404'</code> path again. If this is the behavior you want, switch the last route with <code>{ path: '**', redirectTo: '404' }</code>.</p>



<h2 class="wp-block-heading">Dynamic 404 routes</h2>



<p>Now that we have the static 404 route configured, we can use the router to navigate to it whenever we want to show the not found page to the user.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
this.router.navigate(&#x5B;&#039;/404&#039;], { skipLocationChange: true });
</pre></div>


<p>By using the option <code>skipLocationChange: true</code>, we have the same behavior as mentioned above. Even though the router navigates to the route, the browser URL stays the same, allowing the user to easily go back.</p>



<h3 class="wp-block-heading">Personalizing the 404 message</h3>



<p>You may want to personalize the message shown on the 404 page. One way to do this is using the navigation state.</p>



<p>When navigating to the 404 page, you can include a <code>state</code> in the navigation options.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
this.router.navigate(&#x5B;&#039;/404&#039;], { 
    skipLocationChange: true,
    state: {
        // Whatever data you need on the 404 page
    	source: &#039;article&#039;,
        id: 123456
    }
});
</pre></div>


<p>On your <code>NotFoundComponent</code>, you can access this object in the constructor using the router&#8217;s <a href="https://angular.io/api/router/Router#getcurrentnavigation"><code>getCurrentNavigation</code></a> method.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: jscript; title: ; notranslate">
export class NotFoundComponent {
  constructor(private router: Router) {
    console.log(this.router.getCurrentNavigation().extras.state.source);
  }
}
</pre></div>


<p>You must access the state in the constructor, as it is only available while the router is navigating.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In this post, we saw how to implement a 404 route in Angular. We looked at how we can redirect to it dynamically and even how to personalize the 404 page with route dependent data!</p>



<p>Have questions, corrections, or an alternative way of handling this? Leave a comment or reach out to me on Twitter <a href="https://twitter.com/pedronavelopes">@pedronavelopes</a> and let me know! Thanks for reading!</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2022/05/05/handling-not-found-routes-in-angular/">Handling not found routes in Angular</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/pedrolopes/2022/05/05/handling-not-found-routes-in-angular/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>CSS Scroll Shadows</title>
		<link>https://blogit.create.pt/pedrolopes/2022/03/24/css-scroll-shadows/</link>
					<comments>https://blogit.create.pt/pedrolopes/2022/03/24/css-scroll-shadows/#respond</comments>
		
		<dc:creator><![CDATA[Pedro Lopes]]></dc:creator>
		<pubDate>Thu, 24 Mar 2022 13:52:04 +0000</pubDate>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[FrontEnd Development]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12643</guid>

					<description><![CDATA[<p>Nowadays, it&#8217;s crucial that your webpages are responsive. The problem we sometimes run into, is the fact that some components don&#8217;t adapt well into mobile. In this post, we&#8217;ll look at a way to make scrollable components more intuitive on mobile devices using CSS scroll shadows. Let&#8217;s think of a table. It&#8217;s a collection of [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2022/03/24/css-scroll-shadows/">CSS Scroll Shadows</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Nowadays, it&#8217;s crucial that your webpages are responsive. The problem we sometimes run into, is the fact that some components don&#8217;t adapt well into mobile.</p>



<p>In this post, we&#8217;ll look at a way to make scrollable components more intuitive on mobile devices using CSS scroll shadows.</p>



<p>Let&#8217;s think of a table. It&#8217;s a collection of rows with columned data. One way to make a table responsive is by collapsing each row into a card. This will, however, remove the link between rows for any given column.</p>



<p>An alternative is to make the table scroll horizontally. This gives your data space to breathe and maintains the link given by columns. All done and pretty easy, right? Well, you might run into this problem:</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://digitalpress.fra1.cdn.digitaloceanspaces.com/c8lrmyd/2022/03/table-no-shadow.png" alt="Column of items without an indication that there is more content to the right" /></figure></div>



<p>If your column width happens to match the width of the table element, your users will have no idea that there is extra content to the side.</p>



<h2 class="wp-block-heading">Adding Shadows</h2>



<p>One way to fix this is by using scroll shadows. A scroll shadow is a shadow applied at the border of the element when there is the possibility of scrolling. That same example with a scroll shadow might look like this:</p>



<div class="wp-block-image"><figure class="aligncenter"><img decoding="async" src="https://digitalpress.fra1.cdn.digitaloceanspaces.com/c8lrmyd/2022/03/ScrollShadowsExample.png" alt="3 tables are shown using css scroll shadows. On the left, the table is showing the first column and there is a shadow on the right but not on the left. In the middle, there is a column with shadows on both side. On the right is the last column of the table, showing a shadow on the left but not on the right." /><figcaption>Different scroll positions for the same element using CSS scroll shadows</figcaption></figure></div>



<p>As you can see, the shadow is only visible when there is space to scroll. There are many ways to do this, I&#8217;m going to show you a way that only uses CSS.</p>



<p>First, we start by adding the shadows with two radial gradients.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: css; title: ; notranslate">
.scroll-shadows-h {
  background:
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,0.4), rgba(0,0,0,0)),
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,0.4), rgba(0,0,0,0)) 100% 0;
  background-repeat: no-repeat;
  background-size: 14px 100%, 14px 100%;
}
</pre></div>


<div class="wp-block-image"><figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="214" height="313" src="https://blogit.create.pt/wp-content/uploads/2022/03/imagem.png" alt="" class="wp-image-12651" srcset="https://blogit.create.pt/wp-content/uploads/2022/03/imagem.png 214w, https://blogit.create.pt/wp-content/uploads/2022/03/imagem-205x300.png 205w" sizes="(max-width: 214px) 100vw, 214px" /></figure></div>



<h2 class="wp-block-heading">Hiding the shadows</h2>



<p>This results in the shadows being visible even when there isn&#8217;t space to scroll. To fix this, we add shadow covers that hide the shadows at the beginning and end of the element, instead of its viewport.</p>



<p>We can implement this using the <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/background-attachment">background-attachment</a> property. To quote the MDN, &#8220;The <code>background-attachment</code> CSS property sets whether a background image&#8217;s position is fixed within the viewport, or scrolls with its containing block&#8221;.</p>



<p>Setting the <code>background-attachment</code> of the shadow covers to <code>local</code>, means that they are fixed relative to the content of the element. When we scroll inside the element, the background scrolls as well.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: css; title: ; notranslate">
.scroll-shadows-h {
  background:
    /* Shadow covers */
    linear-gradient(to right, #fff 30%, rgba(255,255,255,0)),
    linear-gradient(to right, rgba(255,255,255,0), #fff 70%) 100% 0,
   
    /* Shadows */
    radial-gradient(farthest-side at 0 50%, rgba(0,0,0,0.4), rgba(0,0,0,0)),
    radial-gradient(farthest-side at 100% 50%, rgba(0,0,0,0.4), rgba(0,0,0,0)) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}
</pre></div>


<p>This class is the class used in the example in the image above. The cool thing about this implementation is that it&#8217;s very versatile. We can apply it vertically or use any background we want to. You could replace the shadows with an image (e.g. an arrow) and this effect would still work, as the covers will continue to overlap it. Check the <a href="https://codepen.io/pedronave/pen/ZEvpwZP">CodePen below</a> for some examples!</p>



<figure class="wp-block-embed is-type-wp-embed is-provider-codepen wp-block-embed-codepen"><div class="wp-block-embed__wrapper">
<iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted" title="CSS Scroll Shadows" src="https://codepen.io/pedronave/embed/preview/ZEvpwZP?default-tabs=html%2Cresult&#038;height=300&#038;host=https%3A%2F%2Fcodepen.io&#038;slug-hash=ZEvpwZP#?secret=NySH3eOTBD" data-secret="NySH3eOTBD" scrolling="no" frameborder="0" height="300"></iframe>
</div></figure>



<p>Thanks for reading! Do you find this useful? Do you think there are better ways to achieve this effect? Let me know in the comments below, or reach out to me on Twitter <a href="https://twitter.com/pedronavelopes">@pedronavelopes</a>!</p>



<p>This blog post was inspired by Lea Verou&#8217;s post &#8220;<a href="https://lea.verou.me/2012/04/background-attachment-local/"><em>Pure CSS scrolling shadows with background-attachment: local</em></a>&#8220;. Go check it out!</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2022/03/24/css-scroll-shadows/">CSS Scroll Shadows</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/pedrolopes/2022/03/24/css-scroll-shadows/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>10 easy ways to improve web accessibility</title>
		<link>https://blogit.create.pt/pedrolopes/2021/09/10/10-easy-ways-to-improve-web-accessibility/</link>
					<comments>https://blogit.create.pt/pedrolopes/2021/09/10/10-easy-ways-to-improve-web-accessibility/#respond</comments>
		
		<dc:creator><![CDATA[Pedro Lopes]]></dc:creator>
		<pubDate>Fri, 10 Sep 2021 12:37:40 +0000</pubDate>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[FrontEnd Development]]></category>
		<guid isPermaLink="false">https://blogit.create.pt/?p=12548</guid>

					<description><![CDATA[<p>When you first start learning about accessibility, it may seem daunting to make your current projects more accessible. In this post, I&#8217;ll give you some easy steps to make this process a bit easier. I would like you to keep in mind that this will not make your website fully accessible, it&#8217;s just an easy [&#8230;]</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2021/09/10/10-easy-ways-to-improve-web-accessibility/">10 easy ways to improve web accessibility</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>When you first start learning about accessibility, it may seem daunting to make your current projects more accessible. In this post, I&#8217;ll give you some easy steps to make this process a bit easier.</p>



<p>I would like you to keep in mind that this will not make your website fully accessible, it&#8217;s just an easy way to vastly improve accessibility.</p>



<h2 class="wp-block-heading">1 &#8211; Follow WCAG and WebAIM checklist</h2>



<p>The WCAG (Web Content Accessibility Guidelines) is a set of guidelines on how the web can be made more accessible. It takes 4 principles into consideration:</p>



<ol class="wp-block-list"><li>Perceivable &#8211; Just because something is perceivable with one sense (usually sight), not all users can perceive it</li><li>Operable &#8211; Can users use UI components and navigate the content. For example, hover interactions can&#8217;t be operated by someone without a mouse</li><li>Understandable &#8211; Can all users understand the content</li><li>Robust &#8211; Is it robust enough for the content to be consumed by a wide variety of user agents, and does it work with accessibility tools.</li></ol>



<p>The <a href="https://webaim.org/standards/wcag/checklist" target="_blank" rel="noreferrer noopener">WebAIM Checklist</a> was created from these guidelines and simplified the implementation of these principles. This checklist should be seen as a companion to start implementing accessible interfaces, not as the final resource on what make a website accessible.</p>



<h2 class="wp-block-heading">2 &#8211; Provide alternatives to non-text content</h2>



<p>Non-sighted users may have a hard time taking in non-text content, as such, <a href="https://www.w3.org/TR/WCAG21/#non-text-content">it&#8217;s important to provide alternatives to these</a>.</p>



<ul class="wp-block-list"><li>Provide alt text for images The alt text should be an alternative to the image content<ul><li>If an image is not relevant for the context, you can hide it from screen readers by providing an empty alt text.</li></ul></li><li>Use aria-label for other elements<ul><li>The aria-label lets you label elements for screen readers</li></ul></li></ul>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
// 👎 No descriptive alt text
&lt;img src=&quot;puppy.jpg&quot;&gt;

// 👍 Descriptive alt text
&lt;img src=&quot;puppy.jpg&quot; alt=&quot;Labrador puppy running in the grass&quot;&gt;

// 👍 Empty alt text excludes the image that isn&#039;t relevant
&lt;button&gt;
	&lt;img src=&quot;home-icon.jpg&quot; alt=&quot;&quot;&gt;
	Home
&lt;/button&gt;
</pre></div>


<h2 class="wp-block-heading">3 &#8211; Use native and semantic elements</h2>



<p>When implementing an HTML page, try to <a href="https://www.w3.org/TR/WCAG21/#info-and-relationships">use native and semantic elements</a>.</p>



<p>If you need a button, you should use a &lt;button&gt; element, not a div with an onclick event or an anchor link.</p>



<p>This is the case because different elements mean different things, and have different behaviors. By using the native HTML elements, we know it will have the expected behavior. And by using a semantic element, we ensure that the user understands what the element will do, as in, a button will trigger an action, and a link will trigger a navigation to somewhere else.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
// 👎 Non-semantic element
&lt;div class=&quot;button&quot; click=&quot;onclick&quot;&gt;
	Click me!
&lt;/div&gt;

// 👍 Semantic element
&lt;button click=&quot;onclick&quot;&gt;
	Click me!
&lt;/button&gt;
</pre></div>


<h2 class="wp-block-heading">4 &#8211; Use ARIA attributes in elements</h2>



<p>When there is no native element which matches your need, you may have to implement it yourself.</p>



<p>To make sure the element you are implementing is accessible, you should use ARIA (Accessible Rich Internet Applications) attributes.</p>



<p>These will allow you to add semantics to elements which have no meaning, modify existing semantics, add extra labels and descriptions, express relationships between elements, etc.</p>



<p>The <a href="https://www.w3.org/TR/wai-aria-practices-1.1/">ARIA practices document</a> specifies the patterns that each element should have. When implementing an element, you give it a role and commit to following all the patterns and interactions defined in the ARIA practices.</p>



<h2 class="wp-block-heading">5 &#8211; Understand focus and tab order</h2>



<p>Tab order refers to the order in which the items on a page will be focused using the keyboard.</p>



<p>Some elements are implicitly focusable (such as inputs, buttons and links), and are added to the tab order automatically.</p>



<p>The tab order is determined by the <strong>DOM order,</strong> but this can be different from the <strong>visual order</strong> which can be changed by CSS. Therefore, <a href="https://www.w3.org/TR/WCAG21/#focus-order">you should make sure that the reading and navigation order are logical and intuitive</a>.</p>



<p>To change the tab order, you can use the tab index attribute:</p>



<ul class="wp-block-list"><li>-1<ul><li>Removes the element from the natural tab order, but it is focusable through code.</li><li>Useful when we have hidden elements (such as modals) which should not be focusable when hidden</li></ul></li><li>0<ul><li>Adds the element to the natural tab order.</li><li>Allows elements to be focused and receive keyboard input.</li></ul></li><li>0<ul><li>Jumps element to the front of the tab order</li><li>If there are multiple elements, order goes from lowest to highest</li><li><strong>This is discouraged</strong> because it can make it confusing for screen readers, as they navigate the page linearly</li></ul></li></ul>



<p><strong><a href="https://www.w3.org/TR/WCAG21/#focus-visible">Make sure you have a focus ring</a>.</strong> A focus ring lets users know which element is focused. This is essential for keyboard users.</p>



<h2 class="wp-block-heading">6 &#8211; Bypass Blocks</h2>



<p>If your page has a lot of navigation links, a keyboard user will have to tab through all these links before being able to reach the main content. To make your website more convenient to use, you can provide users with a <a href="https://webaim.org/techniques/skipnav/">skip link</a>.</p>



<p>The skip link will be the first focusable element on the page and links the user to the main content, skipping the focus to it directly.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: xml; title: ; notranslate">
&lt;body&gt;
  &lt;a href=&quot;#maincontent&quot;&gt;Skip to main content&lt;/a&gt;
  &lt;!-- Navigation links ---&gt;
  &lt;main id=&quot;maincontent&quot;&gt;
    &lt;h1&gt;Heading&lt;/h1&gt;
    &lt;p&gt;This is the first paragraph&lt;/p&gt;
  &lt;/main&gt;
&lt;/body&gt;
</pre></div>


<p>To make sure the skip link doesn&#8217;t affect your page, you can hide it until it is focused, meaning only keyboard users will see it.</p>



<p>Alternatively to skip links, if you provide a proper <strong>heading structure</strong>, screen readers will also be able to skip around the page and navigate to each section much more easily. This will, however, not provide a skip mechanism for users who just use the keyboard to navigate.</p>



<h2 class="wp-block-heading">7 &#8211; Use ARIA attributes in CSS selectors</h2>



<p>You can use ARIA attributes in your CSS selectors. This makes sure that ARIA is being used correctly, and removes the need for additional selectors.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: css; title: ; notranslate">
// 👎 Aditional selector
.toggle.pressed

// 👍 ARIA attributes
.toggle&#x5B;aria-pressed=&quot;true&quot;]
</pre></div>


<h2 class="wp-block-heading">8 &#8211; Responsive design</h2>



<p>Even if you don&#8217;t need to implement mobile designs, a responsive design ensures that the user can zoom in the page and the content adjusts properly. <a href="https://www.w3.org/TR/WCAG21/#resize-text">Your page should be zoomable up to 200% without losing content or functionality.</a></p>



<ul class="wp-block-list"><li>Use relative font-size, allowing the browser to rescale the text</li><li>Use appropriate touch targets (&gt;48px) so users have enough space to touch a single button</li><li>Space touch targets about 32px from each other</li></ul>



<h2 class="wp-block-heading">9 &#8211; Color and Contrast</h2>



<p><a href="https://webaim.org/resources/contrastchecker/">There are tools which allow you to easily check for contrast</a>. Some browsers even let you check this directly in the dev tools.</p>



<p>You also have to keep in mind that some users will not be able to distinguish some colors. As such, <strong><a href="https://www.w3.org/TR/WCAG21/#use-of-color">information should not be conveyed by color alone</a>.</strong> Make sure you add other elements (such as captions or icons) to indicate the state of the elements.</p>



<div class="wp-block-image"><figure class="aligncenter size-full"><img decoding="async" width="671" height="170" src="https://blogit.create.pt/wp-content/uploads/2021/09/Compare-colorblind2.png" alt="On the left, two form fields using green and red to convey their status. On the right, a view of the same forms is shown, simulating red/green color blindness. Both these fields are the same color." class="wp-image-12551" srcset="https://blogit.create.pt/wp-content/uploads/2021/09/Compare-colorblind2.png 671w, https://blogit.create.pt/wp-content/uploads/2021/09/Compare-colorblind2-300x76.png 300w" sizes="(max-width: 671px) 100vw, 671px" /><figcaption>Comparison of interface using only color as a state indicator. Colorblind people will not be able to distinguish these colors</figcaption></figure></div>



<h2 class="wp-block-heading">10 &#8211; How to apply these tips</h2>



<p>Good accessibility ensures good UX. As such, accessibility should be focused from the beginning of development.</p>



<p>When this doesn&#8217;t happen, we inevitably have to fix accessibility issues later. You can identify some issues using the following techniques:</p>



<ul class="wp-block-list"><li>Use the accessibility inspector included in the browser</li><li>Navigate through your website using only a keyboard</li><li>Simulate impaired vision through browser extensions (e.g. <a href="https://addons.mozilla.org/en-US/firefox/addon/nocoffee/">NoCoffee</a>)</li></ul>



<p>After identifying some issues, how should we tackle them? As with bugs, we should focus on high impact, low effort issues.</p>



<ul class="wp-block-list"><li>How frequently is this piece of UI used?</li><li>How badly does this affect our users?</li><li>How expensive is it to fix?</li></ul>



<h2 class="wp-block-heading">Conclusion</h2>



<p>Accessibility is starting to make it to the front of developer concerns. With more popularity come more resources to help us develop better interfaces and experiences for all users.</p>



<p>Hopefully, this article provided you with an initial idea on how to approach web accessibility.</p>
<p>The post <a href="https://blogit.create.pt/pedrolopes/2021/09/10/10-easy-ways-to-improve-web-accessibility/">10 easy ways to improve web accessibility</a> appeared first on <a href="https://blogit.create.pt">Blog IT</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blogit.create.pt/pedrolopes/2021/09/10/10-easy-ways-to-improve-web-accessibility/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
