{"id":712,"date":"2020-07-16T11:16:00","date_gmt":"2020-07-16T05:46:00","guid":{"rendered":"http:\/\/crayond.com\/blog\/?p=712"},"modified":"2023-02-22T15:39:12","modified_gmt":"2023-02-22T10:09:12","slug":"web-design-hacks","status":"publish","type":"post","link":"https:\/\/www.crayond.com\/blog\/web-design-hacks\/","title":{"rendered":"9 Simple Hacks Every Web Designer Should Know [code snippets included]"},"content":{"rendered":"\n<p>People spend a lot of time on their phones but that still has not made web pages irrelevant.<br><\/p>\n\n\n\n<p>On the contrary, websites have come to look as sleek as mobile apps in recent days due to new CSS specs and UX trends.<br><\/p>\n\n\n\n<p>As a front-end developer, you\u2019d need to be on the lookout for these emerging techniques. You\u2019d have to go beyond style sheets and templates, framing pages dictated by the UX.<br><\/p>\n\n\n\n<p>And so, here are a few simple hacks and tricks that you can employ in your code to make your creations look current.<br><\/p>\n\n\n\n<p>Let\u2019s jump into it.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2>Validating forms using the \u2018Pattern\u2019 attribute in HTML5<\/h2>\n\n\n\n<p>Forms are all over the internet. Whether you sign up for a new social media account or a magazine subscription, you have to deal with date-of-births and addresses.<br><\/p>\n\n\n\n<p>To make it easier on the user\u2019s end, you can use the pattern attribute and invalidate wrong user inputs.<br><\/p>\n\n\n\n<p>Look at this code here:<br><\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container\">\n<pre class=\"wp-block-verse\"><br>&nbsp;<br>&lt;form action=\"\/front_page.php\"&gt;<br>Password: &lt;input type=\"password\" name=\"pw\" pattern=\"[a-z].{1,15,}\"&gt;<br>&lt;input type=\"submit\"&gt;<br>&lt;\/form&gt;<br><br><\/pre>\n<\/div><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>Here, you create a field that accepts text that is lowercase and not longer than 15 characters.<br><\/p>\n\n\n\n<p>You can customize your field to contain different parameters. The [] lets you choose the range while the {} lets you set the limit on the input.<br><\/p>\n\n\n\n<h2>Load above-the-fold assets quicker for better PageRank<\/h2>\n\n\n\n<p>Making your webpage load faster, especially the very first elements that a prospective user would view is important.<br><\/p>\n\n\n\n<p>This is because these load times are taken into consideration by Google\u2019s search bots as they rank your website.<br><br>Here are a few suggestions:<br><\/p>\n\n\n\n<ul><li>Ensure that all of your CSS is inline.&nbsp;<\/li><li>Decrease the number of external files you use to load your web pages&#8217; elements.&nbsp;<\/li><li>Use the right CSS media types and queries to specify critical resources as non-render blocking.<\/li><li>Put the &lt;content&gt; section before &lt;sidebar&gt;.<\/li><li>Embed the font data to speed up fonts loading.<\/li><\/ul>\n\n\n\n<h2>Use Gzip compression in HTML5 to increase page-loading speed<\/h2>\n\n\n\n<p>Instead of using an index.html file, you can dispatch a .zip that would be unpacked by the browser.<br><\/p>\n\n\n\n<p>To do that, first locate your htaccess file on your web host and then use this snippet to modify it:<\/p>\n\n\n\n<pre class=\"wp-block-verse\"><br>&lt;ifModule mod_gzip.c&gt;<br>mod_gzip_on Yes<br>mod_gzip_dechunk Yes<br>mod_gzip_item_include file .(html?|txt|css|js|php|pl)$<br>mod_gzip_item_include handler ^cgi-script$<br>mod_gzip_item_include mime ^text\/.*<br>mod_gzip_item_include mime ^application\/x-javascript.*<br>mod_gzip_item_exclude mime ^image\/.*<br>mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*<br>&lt;\/ifModule&gt;<br><br><br><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2>Use HMTL5 Local Storage to decrease bandwidth usage<\/h2>\n\n\n\n<p>Cookies are used to store user information and to enable their sessions on your websites. However, cookies are resource-intensive, as they are constantly sent back and forth between you and the user.<br><\/p>\n\n\n\n<p>Instead, you can choose to store the user data locally. Follow this link to learn more on that: <a href=\"http:\/\/tutorials.jenkov.com\/html5\/local-storage.html\">http:\/\/tutorials.jenkov.com\/html5\/local-storage.html<\/a><br><\/p>\n\n\n\n<h2>Curve text around an image<\/h2>\n\n\n\n<p>Gone are the days when the image had to be a rectangle for text to fit below or aside it. With SVGs and better CSS specs, you can now load images of any shape on your webpage, and using the shape-outside element, you can display the text around it.<br><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><br>&lt;ifModule mod_gzip.c&gt;<br>mod_gzip_on Yes<br>mod_gzip_dechunk Yes<br>mod_gzip_item_include file .(html?|txt|css|js|php|pl)$<br>mod_gzip_item_include handler ^cgi-script$<br>mod_gzip_item_include mime ^text\/.*<br>mod_gzip_item_include mime ^application\/x-javascript.*<br>mod_gzip_item_exclude mime ^image\/.*<br>mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*<br>&lt;\/ifModule&gt;<br><br><\/pre>\n\n\n\n<p>As per your image\u2019s alignment, you can alter this snippet.<br><\/p>\n\n\n\n<h2>Native animations using CSS<\/h2>\n\n\n\n<p>With CSS3 specs, it is now possible to animate SVGs inline on a web page. This means that simple ornamentation would not require JavaScript or other tools.&nbsp;&nbsp;<br><\/p>\n\n\n\n<p>Using the @keyframes rule, you can type out your code to animate a picture. Check out this collection to learn more: <a href=\"https:\/\/codepen.io\/collection\/yivpx\/\">https:\/\/codepen.io\/collection\/yivpx\/<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2>Smart Quotes<\/h2>\n\n\n\n<p>Smart quotes have taken over the reading experience of the modern web user, due to publications like Medium. It enhances the reading experience while making necessary information stand out.&nbsp;<br><\/p>\n\n\n\n<p>On HTML, it is a simple &lt;q&gt; tag that does not leave much room for customization.<br><\/p>\n\n\n\n<pre class=\"wp-block-verse\">&lt;q&gt;Smart quotes are beautiful!&lt;\/q&gt;<br><\/pre>\n\n\n\n<p>With CSS, using its \u2018q\u2019 rule, you can customize the font and size as well.<br><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><br>q {<br>&nbsp;&nbsp;&nbsp;&nbsp;quotes: \"\u201c\" \"\u201d\";<br>&nbsp;&nbsp;&nbsp;&nbsp;font-size: 2rem;<br>}<br><br><\/pre>\n\n\n\n<h2>Display error messages when image-loading breaks&nbsp;<\/h2>\n\n\n\n<p>Images can break while loading on the browser due to various reasons. Displaying a broken image icon among the other modern elements might seem a bit outdated.<br><\/p>\n\n\n\n<p>So, you can display a message as well.<br><\/p>\n\n\n\n<p>Here is the CSS snippet:<br><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><br>img {<br>&nbsp;&nbsp;font-family: 'Helvetica';<br>&nbsp;&nbsp;font-weight: 300;<br>&nbsp;&nbsp;line-height: 2;&nbsp;&nbsp;<br>&nbsp;&nbsp;text-align: center;<br>&nbsp;&nbsp;width: 100%;<br>&nbsp;&nbsp;height: auto;<br>&nbsp;&nbsp;display: block;<br>&nbsp;&nbsp;position: relative;<br>}<br><br>img:before {&nbsp;<br>&nbsp;&nbsp;content: \"We're sorry, the image below is broken :(\";<br>&nbsp;&nbsp;display: block;<br>&nbsp;&nbsp;margin-bottom: 10px;<br>}<br><br>img:after {&nbsp;<br>&nbsp;&nbsp;content: \"(url: \" attr(src) \")\";<br>&nbsp;&nbsp;display: block;<br>&nbsp;&nbsp;font-size: 12px;<br>}<br><br><\/pre>\n\n\n\n<h2>Image filters<\/h2>\n\n\n\n<p>Now in CSS, you can employ some basic filters on your image while displaying them on your website without needing to process them using Photoshop. Here is the snippet:<br><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><br>.image img {<br>&nbsp;&nbsp;max-width: 300px;<br>}<br><br>.blur {<br>&nbsp;&nbsp;filter: blur(5px);<br>}<br><br>.grayscale {<br>&nbsp;&nbsp;filter: grayscale(100%);<br>}<br><br>.brightness {<br>&nbsp;&nbsp;filter: brightness(150%);<br>}<br><br>.saturate {<br>&nbsp;&nbsp;filter: saturate(200%);<br>}<br><br>.invert {<br>&nbsp;&nbsp;filter: invert(100%);<br>}<br><br>.huerotate {<br>&nbsp;&nbsp;filter: hue-rotate(180deg);<br><br><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h2>Some extra tidbits<\/h2>\n\n\n\n<h3>Dark Mode<\/h3>\n\n\n\n<p>A budding UX trend, Dark Mode has outgrown its days of being a rare customization preference. Entire mobile operating systems like iOS and Android have brought native support to this theme. As a web developer, you can code this into your webpages as well.<br><\/p>\n\n\n\n<p>There are several ways to do that, the commonest being using the body tag.<br><\/p>\n\n\n\n<p>In our example using CSS, you can see that we create a separate body tag with a different color scheme.<br><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><br>body {<br>&nbsp;&nbsp;--text-color: #222;<br>&nbsp;&nbsp;--bkg-color: #fff;<br>}<br>body.dark-theme {<br>&nbsp;&nbsp;--text-color: #eee;<br>&nbsp;&nbsp;--bkg-color: #121212;<br>}<br><br><\/pre>\n\n\n\n<p>This just creates the theme specification. You\u2019d have to then create a toggle that can activate the dark mode, and for that, you\u2019d need Javascript.<br><\/p>\n\n\n\n<h3>Scroll-powered animations<\/h3>\n\n\n\n<p>While you\u2019d need Javascript to frame full-fledged animations, you can create some simple ones using CSS. Here\u2019s how:<br><\/p>\n\n\n\n<p>First, create a custom CSS property using Javascript that knows how far a user has scrolled down a page.<br><\/p>\n\n\n\n<p>Next, use this snippet:<br><\/p>\n\n\n\n<pre class=\"wp-block-verse\"><br>svg {<br>&nbsp;&nbsp;position: fixed;&nbsp;<br>&nbsp;&nbsp;animation: rotate 1s linear infinite;<br>&nbsp;&nbsp;animation-play-state: paused;<br>&nbsp;&nbsp;animation-delay: calc(var(--scroll) * -1s);<br>}<br><br><\/pre>\n\n\n\n<p>To translate what the code means: The SVG stays put and animates itself once the user starts scrolling.<br><\/p>\n\n\n\n<h2>Final words<\/h2>\n\n\n\n<p>Building web pages that function well and look good is no easy task.&nbsp;<br><\/p>\n\n\n\n<p>We also understand that it is not as straightforward as employing a few hacks and must-dos.&nbsp;<br><\/p>\n\n\n\n<p>But we hope that these give you some mileage in your development.<br><\/p>\n\n\n\n<p>Follow us on the socials and browse around for more such articles.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>People spend a lot of time on their phones but that still has not made web pages irrelevant. On the contrary, websites have come to look as sleek as mobile apps in recent days due to new CSS specs and UX trends. As a front-end developer, you\u2019d need to be on the lookout for these [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2403,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/posts\/712"}],"collection":[{"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/comments?post=712"}],"version-history":[{"count":73,"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/posts\/712\/revisions"}],"predecessor-version":[{"id":3492,"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/posts\/712\/revisions\/3492"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/media\/2403"}],"wp:attachment":[{"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/media?parent=712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/categories?post=712"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.crayond.com\/blog\/wp-json\/wp\/v2\/tags?post=712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}