{"id":25070,"date":"2015-11-13T21:01:14","date_gmt":"2015-11-13T13:01:14","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=25070"},"modified":"2022-07-15T17:07:04","modified_gmt":"2022-07-15T09:07:04","slug":"skewed-edges-css","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/","title":{"rendered":"How to Create Skewed Edges With CSS"},"content":{"rendered":"<p>In this post, we\u2019re going to look at how we can create a  angled  edge effect (horizontally) on a web page. Basically, it looks something like this:<\/p>\n<p>Having a slightly angled edge should make our web layout look less rigid and dull. To do this trick, we will be using the <strong>pseudo-elements<\/strong> <code>::before<\/code> and <code>::after<\/code> and <strong>CSS3 Transform<\/strong>.<\/p>\n<h2>Using Pseudo Elements<\/h2>\n<p>This technique uses the pseudo-elements <code>::before<\/code> and <code>::after<\/code> to angle the element edges. In this example, we will be adjusting the bottom edge.<\/p>\n<pre>\r\n.block{\r\n\theight: 400px;\r\n\twidth: 100%;\r\n\tposition: relative;\r\n\tbackground: linear-gradient(to right, rgba(241,231,103,1) 0%, rgba(254,182,69,1) 100%);\r\n}\r\n.block::after{\r\n\tcontent: '';\r\n\twidth: 100%;\r\n\theight: 100%;\r\n\tposition: absolute;\r\n\tbackground: inherit;\r\n\tz-index: -1;\r\n\tbottom: 0;\r\n\ttransform-origin: left bottom;\r\n\ttransform: skewY(3deg);\r\n}\r\n<\/pre>\n<p>Let\u2019s recap.<\/p>\n<p>The <code>transform-origin<\/code> specifies the coordinates of the element we want to transform. In the example above we specified <code>left bottom<\/code> that will put the starting coordinates on the bottom-left side of the block.<\/p>\n<p>The <code>transform: skewY(3deg);<\/code> makes the <code>::after<\/code> block skew or angle at 3 degrees. Since we specified the starting coordinate as bottom-left, the bottom-right of the block raises 3 degrees. If we swap the <code>transform-origin<\/code> to <code>right bottom<\/code> and the bottom-left corner will be raised 3 degrees instead.<\/p>\n<p>You can add a solid color background or gradient to see the result.<\/p>\n<p><iframe height=\"300\" scrolling=\"no\" src=\"https:\/\/codepen.io\/\/agusesetiyono\/embed\/bVMaBm\/?height=300&default-tab=result\" frameborder=\"no\" allowtransparency=\"true\" allowfullscreen=\"true\" style=\"width: 100%;\"><\/iframe><\/p>\n<h2>Make It Easier with Sass Mixin<\/h2>\n<p>To make this easier, I have created a Sass mixin to add the angled edges, minus the headaches from dealing with the complexities of style rules. With the following mixin you can quickly specify the side \u2013 top-left, top-right, bottom-left or bottom-right \u2013  to skew.<\/p>\n<pre>\r\n@mixin angle-edge($pos-top:null, $angle-top:null, $pos-btm:null, $angle-btm:null){\r\n\twidth: 100%;\r\n\tposition: relative;\r\n\tbackground: linear-gradient(to right, rgba(241,231,103,1) 0%, rgba(254,182,69,1) 100%);\r\n\t&::before,\r\n\t&::after{\r\n\t\tcontent: '';\r\n\t\twidth: 100%;\r\n\t\theight: 100%;\r\n\t\tposition: absolute;\r\n\t\tbackground: inherit;\r\n\t\tz-index: -1;\r\n\t\ttransition: ease all .5s;\r\n\t}\r\n\r\n\t@if $pos-top{\r\n\t\t&::before{\r\n\t\t\t@if $pos-top == 'topleft'{\r\n\t\t\t\ttop: 0;\r\n\t\t\t\ttransform-origin: right top;\r\n\t\t\t\ttransform: skewY($angle-top);\r\n\t\t\t}\r\n\t\t\t@if $pos-top == 'topright' {\r\n\t\t\t\ttop: 0;\r\n\t\t\t\ttransform-origin: left top;\r\n\t\t\t\ttransform: skewY(-$angle-top);\r\n\t\t\t} \r\n\t\t}\r\n\t}\r\n\r\n\t@if $pos-btm{\r\n\t\t&::after{\r\n\t\t\t@if $pos-btm == 'bottomleft' {\r\n\t\t\t\tbottom: 0;\r\n\t\t\t\ttransform-origin: right bottom;\r\n\t\t\t\ttransform: skewY(-$angle-btm);\r\n\r\n\t\t\t} \r\n\r\n\t\t\t@if $pos-btm == 'bottomright' {\r\n\t\t\t\tbottom: 0;\r\n\t\t\t\ttransform-origin: left bottom;\r\n\t\t\t\ttransform: skewY($angle-btm);\r\n\t\t\t} \r\n\t\t}\r\n\t}\r\n}\r\n<\/pre>\n<p>There are four variables in the mixin. The first two variables, <code>$pos-top<\/code> and <code>$angle-top<\/code>, specify the <strong>top starting coordinate<\/strong> and the <strong>degree<\/strong>. The latter two variables specify the <strong>coordinate <\/strong>and the<strong> degree <\/strong>for the<strong> bottom <\/strong>side.<\/p>\n<p>If you fill up all four variables you can angle both sides \u2013 top and bottom \u2013 of the element.<\/p>\n<p>Use the Sass <code>@include<\/code> syntax to insert the mixin to an element. You can see examples below:<\/p>\n<p>To add skewed edge on <strong>top-left<\/strong> side:<\/p>\n<pre>\r\n.block{\r\n\t@include angle-edge(topleft, 3deg);\r\n}\r\n<\/pre>\n<p>To add skewed edge on <strong>bottom-right<\/strong> side:<\/p>\n<pre>\r\n.block{\r\n\t@include angle-edge(bottomright, 3deg);\r\n}\r\n<\/pre>\n<p>To add skewed edge on <strong>top-left<\/strong> and <strong>bottom-right<\/strong> side:<\/p>\n<pre>\r\n.block{\r\n\t@include angle-edge(topleft, 3deg, bottomright, 3deg);\r\n}\r\n<\/pre>\n<p>Below is the demo with the mixins applied. Change the select box to toggle to another style.<\/p>\n<p><iframe height=\"550\" scrolling=\"no\" src=\"https:\/\/codepen.io\/\/tfirdaus\/embed\/pjqrpe\/?height=550&default-tab=result\" frameborder=\"no\" allowtransparency=\"true\" allowfullscreen=\"true\" style=\"width: 100%;\"><\/iframe><\/p>\n<p>That\u2019s it!<\/p>","protected":false},"excerpt":{"rendered":"<p>In this post, we\u2019re going to look at how we can create a angled edge effect (horizontally) on a web page. Basically, it looks something like this: Having a slightly angled edge should make our web layout look less rigid and dull. To do this trick, we will be using the pseudo-elements ::before and ::after&hellip;<\/p>\n","protected":false},"author":141,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[507,4501],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Create Skewed Edges With CSS - Hongkiat<\/title>\n<meta name=\"description\" content=\"In this post, we&#039;re going to look at how we can create a angled edge effect (horizontally) on a web page. Basically, it looks something like this: Having\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Skewed Edges With CSS\" \/>\n<meta property=\"og:description\" content=\"In this post, we&#039;re going to look at how we can create a angled edge effect (horizontally) on a web page. Basically, it looks something like this: Having\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-13T13:01:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-15T09:07:04+00:00\" \/>\n<meta name=\"author\" content=\"Agus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bagusdesain\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Agus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/\"},\"author\":{\"name\":\"Agus\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/b23dad06815dff0bcc222088bed549dd\"},\"headline\":\"How to Create Skewed Edges With CSS\",\"datePublished\":\"2015-11-13T13:01:14+00:00\",\"dateModified\":\"2022-07-15T09:07:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/\"},\"wordCount\":336,\"commentCount\":7,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"CSS\",\"CSS Tutorials\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/\",\"name\":\"How to Create Skewed Edges With CSS - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2015-11-13T13:01:14+00:00\",\"dateModified\":\"2022-07-15T09:07:04+00:00\",\"description\":\"In this post, we're going to look at how we can create a angled edge effect (horizontally) on a web page. Basically, it looks something like this: Having\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/skewed-edges-css\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Skewed Edges With CSS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/b23dad06815dff0bcc222088bed549dd\",\"name\":\"Agus\",\"description\":\"Agus is a music enthusiast, backpacker and code writer. He has an ambition to build a Skynet on top of HTML and CSS.\",\"sameAs\":[\"https:\\\/\\\/x.com\\\/bagusdesain\"],\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/agus\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Create Skewed Edges With CSS - Hongkiat","description":"In this post, we're going to look at how we can create a angled edge effect (horizontally) on a web page. Basically, it looks something like this: Having","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Skewed Edges With CSS","og_description":"In this post, we're going to look at how we can create a angled edge effect (horizontally) on a web page. Basically, it looks something like this: Having","og_url":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2015-11-13T13:01:14+00:00","article_modified_time":"2022-07-15T09:07:04+00:00","author":"Agus","twitter_card":"summary_large_image","twitter_creator":"@bagusdesain","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Agus","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/"},"author":{"name":"Agus","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/b23dad06815dff0bcc222088bed549dd"},"headline":"How to Create Skewed Edges With CSS","datePublished":"2015-11-13T13:01:14+00:00","dateModified":"2022-07-15T09:07:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/"},"wordCount":336,"commentCount":7,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["CSS","CSS Tutorials"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/","url":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/","name":"How to Create Skewed Edges With CSS - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2015-11-13T13:01:14+00:00","dateModified":"2022-07-15T09:07:04+00:00","description":"In this post, we're going to look at how we can create a angled edge effect (horizontally) on a web page. Basically, it looks something like this: Having","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/skewed-edges-css\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Skewed Edges With CSS"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/b23dad06815dff0bcc222088bed549dd","name":"Agus","description":"Agus is a music enthusiast, backpacker and code writer. He has an ambition to build a Skynet on top of HTML and CSS.","sameAs":["https:\/\/x.com\/bagusdesain"],"url":"https:\/\/www.hongkiat.com\/blog\/author\/agus\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-6wm","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/25070","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=25070"}],"version-history":[{"count":3,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/25070\/revisions"}],"predecessor-version":[{"id":26887,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/25070\/revisions\/26887"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=25070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=25070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=25070"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=25070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}