Tag Archives: firefox

It’s Time To Start Using CSS Custom Properties

Today, CSS preprocessors are a standard for web development. One of the main advantages of preprocessors is that they enable you to use variables. This helps you to avoid copying and pasting code, and it simplifies development and refactoring.

It's Time To Start Using CSS Custom Properties

We use preprocessors to store colors, font preferences, layout details — mostly everything we use in CSS. But preprocessor variables have some limitations.

The post It’s Time To Start Using CSS Custom Properties appeared first on Smashing Magazine.

This article is from:

It’s Time To Start Using CSS Custom Properties

Are Your Keyword Rankings You See On Google Correct?

Google Search Results Differ

Have you ever doubted Google? When it comes to the keyword ranking accuracy, we can be skeptical about rank tracker tools we use or SEOs we hired. But when we check rankings manually, we trust our eyes and Google. But you shouldn’t be so careless. Google is clever and agile. They have a massive list of factors that affect the search results they display for you. Even if you see your website in the Number 1 position, it doesn’t mean you really are on top of the world. Your customers may see a very different Top 10. Fortunately, you can…

The post Are Your Keyword Rankings You See On Google Correct? appeared first on The Daily Egg.

See original – 

Are Your Keyword Rankings You See On Google Correct?

Creating One Browser Extension For All Browsers: Edge, Chrome, Firefox, Opera, Brave And Vivaldi

In today’s article, we’ll create a JavaScript extension that works in all major modern browsers, using the very same code base. Indeed, the Chrome extension model based on HTML, CSS and JavaScript is now available almost everywhere, and there is even a Browser Extension Community Group working on a standard.

Creating One Browser Extension For All Browsers: Edge, Chrome, Firefox, Opera, Brave And Vivaldi

I’ll explain how you can install this extension that supports the web extension model (i.e. Edge, Chrome, Firefox, Opera, Brave and Vivaldi), and provide some simple tips on how to get a unique code base for all of them, but also how to debug in each browser.

The post Creating One Browser Extension For All Browsers: Edge, Chrome, Firefox, Opera, Brave And Vivaldi appeared first on Smashing Magazine.

Visit source: 

Creating One Browser Extension For All Browsers: Edge, Chrome, Firefox, Opera, Brave And Vivaldi

How To Secure Your Web App With HTTP Headers

Web applications, be they thin websites or thick single-page apps, are notorious targets for cyber-attacks. In 2016, approximately 40% of data breaches originated from attacks on web apps — the leading attack pattern. Indeed, these days, understanding cyber-security is not a luxury but rather a necessity for web developers, especially for developers who build consumer-facing applications.

How To Secure Your Web App With HTTP Headers

HTTP response headers can be leveraged to tighten up the security of web apps, typically just by adding a few lines of code. In this article, we’ll show how web developers can use HTTP headers to build secure apps. While the code examples are for Node.js, setting HTTP response headers is supported across all major server-side-rendering platforms and is typically simple to set up.

The post How To Secure Your Web App With HTTP Headers appeared first on Smashing Magazine.

Visit site – 

How To Secure Your Web App With HTTP Headers

Variables: The Backbone Of CSS Architecture


When they hit the front-end landscape a few years ago, preprocessors were heralded as the saviour of CSS, bringing modularity, meaning and even a degree of sexiness. Terms like “Sass architecture” became commonplace, ushering in a new generation of CSS developers who occasionally went to excess with their new-found power. The results were marvellous, and sometimes undesirable.

Variables: The Backbone Of CSS Architecture

One of the unpleasant side effects was a preprocessor elitism that continues to persist. Neophyte designers who were just getting their hands dirty with CSS were overwhelmed by an influx of must-have tools and confused by the bitter partisan wars in web development forums.

The post Variables: The Backbone Of CSS Architecture appeared first on Smashing Magazine.

Continued here:  

Variables: The Backbone Of CSS Architecture

Revisiting Firefox’s DevTools


If you do any kind of development for the web, then you know how important tools are, and you like finding tools that make your life easier. Developing and testing new browser features, however, takes time. Between the time a useful tool first appears in an experimental nightly build and the time it’s available for everyone to use in Firefox, a while has passed.

Revisiting Firefox’s DevTools

That’s one of the reasons Mozilla released Firefox Developer Edition in November 2014 as the recommended Firefox browser for developers. It gets new feature updates more quickly so that you can use the latest tools.

The post Revisiting Firefox’s DevTools appeared first on Smashing Magazine.

View article: 

Revisiting Firefox’s DevTools

How Mobile Transformed PPC Marketing in 2015

Mobile-PPC-Cover
As users spend more time on mobile devices, the way we advertise to them has to change.

In the world of pay-per-click marketing, the past year has been as eventful as it’s been rocky. There’s been a litany of new advertising features released from big players like Facebook and Google, but the health of PPC advertising has felt uncertain.

In his State of PPC in 2015 presentation, WordStream CEO and PPC genius Larry Kim revealed that cost-per-click on search advertising is at an all-time high, and searches on desktop have been trending downwards for years. What’s going on?

Larry-Kim-CPC-Slide
A slide from Larry Kim’s State of PPC in 2015.

All of the huge changes happening in PPC right now can be traced back to one thing: mobile. Below, we’ll explore how the continued shift from desktop to mobile is affecting digital advertising – and the technology behemoths that enable it.

The year of mobile, now and forever

Pretty much every year since 2009, it’s been declared that whatever year it was must certainly be the year of mobile!

Year-of_Mobile

The truth is that pretty much every year since the iPhone came out, it’s been the “year of mobile” in some way, be it mobile devices becoming more sophisticated and more usable, an increase in the amount of mobile-optimized content, or increase in the success of mobile ad campaigns.

But 2015 proved that mobile isn’t just important, it’s dominant. In May, Google confirmed that mobile searches overtook desktop searches in at least ten countries including the US and Japan.

The bottom line is that if you haven’t started optimizing your campaigns for mobile visitors, your visitors are already looking elsewhere. Thankfully, there are plenty of steps you can take to start earning leads on mobile pretty quickly.

Click-to-Call

For example, the “click to call” button introduced to Google AdWords in February allows prospects to connect with you over the phone without having to click through to another page, making the conversion pretty much instant.

That’s not going to always be an appropriate call to action, particularly in circumstances where you want to nurture your leads and guide them down the purchasing funnel. Thankfully, making a fully-fledged campaign landing page work on a mobile device is pretty easy, too; Unbounce, for example, automatically generates a mobile-responsive version of your landing page for you.

No matter what steps you take, remember that from now on, every year is the year of mobile.


From now on, EVERY year is the Year of Mobile.
Click To Tweet


The spectre of ad-blockers

While mobile has introduced plenty of new advertising opportunities, those opportunities are severely endangered on desktop devices as the proliferation of ad blockers continues.

Pagefair, a company that allows marketers to present unobtrusive ads that circumvent ad blockers, collaborated with Adobe to produce The 2015 Ad Blocking Report. Not unbiased sources by any means, yet still, their findings were staggering: there are 200 million users worldwide using ad blockers, up 41% from 2014. Worse, they’re costing advertisers an estimated $22 billion a year in revenue.

While mobile – and iOS, in particular – have often been considered by advertisers as safe spaces where ads cannot be blocked, this changed with Apple’s introduction of “content blocking” in iOS 9.

While iOS doesn’t block ads itself, it enables developers to build and release apps that block types of content delivered through Safari. And this doesn’t just mean ads: cookies, images, pop-ups, autoplay videos and a plethora of other content types can be theoretically blocked in Safari if the developer and user choose so.

Many publications have sought to level with readers who are using ad blockers. Tech publication Wired entitled their piece covering the new functionality: Please Don’t Block Our Ads. Here’s How to Block Ads in iOS 9.

Wired-Ad-Blocker

Interestingly enough, the ad asking users to subscribe to the print edition of Wired (outlined in red above) only appears if you have AdBlock enabled. And the URL it leads to? “wired.com/go/failsafe.” Clearly, this ad is a last-ditch effort to make some money out of what’s otherwise a negative-revenue scenario.

Even maker of popular web browser Firefox has entered the content blocking foray, having just this week released Focus for iOS 9, which solely blocks trackers – ads sans tracking mechanisms get through just fine, although most ads in the year 2015 come with tracking baked-in.

Content blocking hasn’t taken off yet on mobile, with publications reporting that only “1 or 2 percent” of their mobile users are using ad blockers. But considering their success on the desktop, combined with the fact that ads on mobile devices are generally more interruptive to the user experience, it’s a threat that marketers everywhere should take seriously.

The good news for advertisers: content blocking extensions only work in Safari, meaning native advertisements – ads delivered within an app, and not the web browser – are unaffected.

And consumer habits have long since shifted away from the browser on mobile devices: in 2014, Nielsen found that mobile users spent 89% of their time within apps versus browsing the web.

In this scenario, there is no company in a stronger position than Facebook.

The war between Google and Facebook

Facebook’s move to the public market was considered “disastrous” when it happened back in 2012, but that was also the same time when Facebook started offering mobile ads – a product they were in a unique position to take advantage of, being the destination app for hundreds of millions of people worldwide.

Since then, mobile ads have pretty much been far-and-away the most important part of Facebook’s business.

Facebook-Growth-Chart

Back in October, I wrote about how the ongoing ad between Facebook and Google was leading to great new advertising products from both companies:

  • Google gave us the Customer Match, which allows you to upload a list of prospects’ email addresses and target (or exclude) those prospects in your campaigns – functionality Facebook has offered for some time

  • Google also introduced the ability to target audiences that it deems similar to the list you uploaded, another feature Facebook already offered; however, in Google’s case, this works only on Gmail and Youtube, and crucially, not search

  • Meanwhile Facebook opened advertising on Instagram to all marketers, along with new features like 30-second videos (compared to users’ 15-second videos) and image carousels

And recently, Facebook introduced detailed targeting, which gives marketers more flexibility in targeting their campaigns by letting them target particular combinations of factors, and letting them exclude other factors. Like so:

Facebook-Detailed-Targeting

This graphic from Facebook shows how basic and detailed targeting combine to form a final audience:

Facebook-Detailed-Targeting-Diagram

But Google isn’t resting on their laurels in the face of the stiff competition. Days ago, Google introduced a new format to AdMob, its in-app ad network. Trial-run ads allow marketers to embed 60-second app demos directly into the ad. And I don’t mean videos – I mean real, functioning apps.

Trial Run Ad gif for SGN
A demo of Candy Crush Saga being played within an ad.

They also announced interactive interstitial ads, another in-app ad format that can be used to make interactive advertisements with HTML5.

Zalora_Gallery_Capture_Phone_2

From TechCrunch:

“For example, early tester Zalora, makers of a fashion shopping app, built an ad that allows users to swipe to discover an exclusive offer. Other app marketers could create ad formats like “scratch off’s,” or use the ads to create swipeable image carousels. They can even use live app content to create real-time ad formats, says Google.”

While both of these ad formats are in beta and won’t be available to all advertisers for some time, it’s obvious that this tit-for-tat between Facebook and Google, centered almost entirely around who will own advertising on mobile devices, is leading to great developments from both sides for advertisers.

The early bird gets the click

TL;DR: PPC in 2015 has been awesome, but also terrifying.

There are countless opportunities being enabled by the proliferation of mobile, but those opportunities come at the cost of abandoning safe, time-tested tactics.

Where do we go from here? I’d have to defer back to Larry Kim:

Don’t fret the loss of old features – be the first to use new features.

The Law of Shitty Clickthroughs dictates that the clickthrough rate of any ad format trends towards zero over time. At first, users respond highly to the novelty of the format, but as humans learn to recognize the patterns of each ad format, they subconsciously tune them out.

So embrace new formats as quickly as possible. Start testing ideas and collecting data immediately. Optimize your campaigns before your competitors even begin looking at the format. The first-mover advantage is real, and it’s huge.


Embrace new ad formats as they come; the first-mover advantage is real and huge.
Click To Tweet


See original article:

How Mobile Transformed PPC Marketing in 2015

Website Review: charmingcharlie.com

VWO recently conducted a giveaway along with Concept Feedback where we promised a free website evaluation by a Concept Feedback expert. Charmingcharlie.com won this contest and Concept Feedback expert Tom Charde along with the team has been working hard to churn out a brilliant review for this website. Read on for a review of CharmingCharlie.com, head to tail.

Analysis Environment

Note that the following analysis was done viewing the site on;

Web – MacBook Pro 15” Retina display (2880 x 1800) | OS X (10.10.3) | Firefox (38.0.1) browser

Mobile – iPhone 5S | iOS (8.3) | Safari browser.


First Impressions

After a quick walkthrough of the website, a couple things are very clear: it has a very clean design, is aesthetically appealing, has an audience-appropriate tone, and provides an impressive product offering. Charming Charlie steers clear of excessively large images and in-your-face promotional messages, which, in itself, is a big win for the user experience.

Brand Messaging

The first big hurdle that we noticed upon visiting the site is that it lacks any kind of site description, positioning statement, brand promise and/or value proposition. Your existing customers may know all about you, but there’s a large, untapped audience you’re overlooking: people who are unfamiliar with your brand.

Here’s a few basic questions one should ask themselves:

  1. How would you describe the company to someone who’s never heard of it?
  2. How does it provide value to its customers?
  3. What differentiates it from the rest of the market?

Here’s what we can make out from a simple research of the brand; Charming Charlie is a retail store (online and offline) with the latest trends in women’s apparel, fashion jewellery, shoes, handbags, accessories and more. This should ideally be mentioned  on the home page and done so in text format.

There are several great copy points on the ‘About’ page that could ideally craft the messaging and help establish a unique tone for Charming Charlie.

  • We’re crazy for color.
  • We live for sparkle.
  • We thrive on making a statement.
  • We know accessories have the power to transform both your outfit and your outlook.
  • Helping every woman, everywhere, find her fabulous.
  • If it feels good, do it. If it looks good, do it in every color.
  • Unleash your one-of-a-kind style.
  • Bring out your most fabulous, fierce and fun self.

Value Proposition

Charming Charlie needs a one-line “hook” statement; something succinct and hard-hitting that can be used as a tagline near the logo and possibly in the header area. The fifth bullet above (Helping every woman, everywhere, find her fabulous) is close, but it’s a bit too long. Consider this;

Charming Charlie
find your fabulous!

Refining the messaging will not only strengthen the brand, but will also boost the search engine rankings for relevant keywords.


Website Analysis

Moving forth we will break our analysis down to 3 categories; Technical analysis, Heuristic analysis and Mobile website analysis.

Technical Analysis

(Desktop)

The first and foremost thing that one should focus on is to ensure a glitch free website experience. Fixing minor bugs is low-hanging fruit, one that you can make a lot of money on. We found some of these conversion killing bugs on Charming Charlie;

GLOBAL-1 Upon arriving, the site immediately forces an intrusive promotional pop-up on the user. We’d recommend running a few tests on this (one without any pop-ups; one with a 15-sec delay; etc) to see if the bounce rate improves.

GLOBAL-1

The top promo banner in the header (scarves) is loading an error message.

GLOBAL-1

The “Quick Views” feature on the “As Seen In” page doesn’t seem to be working; it displays an endless loading spinner.

Many of the text-based graphics throughout the site aren’t retina-ready. (Examples: Charming Charlie logo, media logos in footer, free shipping banner.) Most users won’t experience a difference, but those with retina displays are seeing a pronounced drop in graphic quality.

(Mobile)

The email sign-up page (under “Customer Service”) gives an “invalid certificate” error. Testing this on Mercury Browser also showed similar results.

MOBILE-3 (1)


Heuristic Analysis

Homepage

CharmingCharlie.com’s clean, minimalistic design is one of its major strengths. It sets the tone right away. The homepage’s look and feel is right on target. Design-wise, one thing we’d suggest is tweaking the styling (inconsistent text colors and alignment) and placement (perhaps move to hero image area?) of the promo banners, which seem to jumble up the header space. The area of the homepage with the most room for improvement is the content.

  1. Allocation of page real estate: The current viewport is dominated by a giant slider; an area that can be used much more efficiently. Try reducing the height of the slider images, moving some of the featured products and messages up, and testing for engagement.
  2. Complete absence of copy: There is literally zero copy as HTML text; the entire page is image-based. In addition to accessibility issues and increased page load time, lacking text on the homepage is killing the chances of achieving a decent search engine ranking.
  3. Lack of Clarity around Newsletter sign up form: There is a “Sign up for emails” form in the footer, but there’s no information about what this is for. Think about it from a user’s perspective: “Why should I sign up? What are you going to send me in exchange for giving my personal contact information?” Try adding a brief description near the form or a link which describes what a user can look forward to.

Following is a screenshot of homepage, annotated with things that should be worked upon.

Modified Home Page copy

We’ve also made a quick mockup for one possible way the header might be transformed.

Variation

VWO_proposed-header_TC edits

vs

Control

Home header

Category Browsing

The What’s New category is confusing.

  • It has a combination of “themed” content (Modern Americana, Citrus Splash, Moroccan Muse).
  • A redirect to an existing main category (CC Essentials).
  • An out-of-place sub-category (Best Sellers).

There’s really only one true subcategory that fits here: New Arrivals. To remedy this, simply eliminate the What’s New category entirely by ‘New Arrivals’. Following is a screenshot of the category browsing drop down of Charming Charlie and things that should be worked upon.

Category browsing-1

GLOBAL-1

Also consider sorting the resulting list of categories into two grouped areas: those which are a product type (Jewellery, Handbags, Apparel, Accessories) and then all the others (New Arrivals, Best Sellers, Seasonal, Special Occasion, CC Essentials, Sale). And it may help to separate the two groups in the side nav with a faint line. Check the mockup with these suggestions implemented.

Product Page

The product page looks pretty standard but there are multiple tweaks which can be done to make them convert more. The screenshot below annotates some aspects which can be improved.

Product Page (1)

One other glaring aspect which we noticed was that there is no product review system. It often acts as a social proof and really helps the visitor take a decision on the product page.


Mobile Web

With e-commerce buyers rapidly gravitating towards mobile, fully functional mobile site is a must. CharmingCharlie.com isn’t a true responsive site, but it does have a fairly decent mobile
version.

Home Page

Similar to the desktop site, the mobile version of the homepage suffers from a serious page real estate concern: the promo messages, navigation, utilities, etc take up almost 60% of the initial screen. Reducing the size of this footprint and moving the meat of the content up will almost certainly improve bounce rate and conversions.

MOBILE-1

Store Locator – Visual Hierarchy Issues

With two form fields (styled differently for some reason) interspersed among three large, black buttons — the eye just doesn’t know where to go on this page.

Converting the buttons to links, and adding some space between the main content and the footer (email signup form) should help create a better flow.

MOBILE-2

Product Page Readability

We would recommend increasing the font size of the product page body copy. The size used on the About, Privacy, and other non-product pages is much easier to read — as can be seen below in a side-by-side comparison.

MOBILE-4

This brings us to the end of the website review of Charmingcharlie.com. We definitely hope Charming Charlie would implement these changes and share the results with us. We thank Tom Charde for working rigorously on this review and helping us in bringing this review to such good shape.

We are going to conduct another giveaway very soon; Can’t wait for the giveaway? You can head to Concept Feedback and hire expert services to get your website reviewed in detail.

Cheers!

The post Website Review: charmingcharlie.com appeared first on VWO Blog.

See the article here:  

Website Review: charmingcharlie.com

Creating Responsive Shapes With Clip-Path And Breaking Out Of The Box

CSS’ clip-path property is your ticket to shape-shifting the monotonous, boxy layouts traditionally associated with flat, responsive design. You will begin to think outside the box, literally, and hexagons, stars and octagons will begin to take form on your web pages. Once you get your hands dirty with clip-path, there’s no end to the shapes you can generate, simply by tweaking a few values.

While the focus of this article is on clip-path using polygons with CSS, all of the demos provide a reference to an inline SVG, in order to gain additional support on Firefox. Generating a responsive SVG clipped shape is trivial once you have created a responsive shape with CSS’ clip-path. We’ll look at this in detail later.

Clip-Path, In A Nutshell

Clipping, with the clip-path property, is akin to cutting a shape (like a circle or a pentagon) from a rectangular piece of paper. The property belongs to the “CSS Masking Module Level 1731” specification. The spec states, “CSS masking provides two means for partially or fully hiding portions of visual elements: masking and clipping”.

The first part, i.e. masking, has to do with using a graphical element, such as a PNG image, CSS gradient or SVG element, as a mask to conceal sections of another element.

The second part, i.e. clip-path, involves a closed vector path, which could be a basic shape defined in CSS or an SVG using the clipPath tag. The region inside this path is displayed, and everything beyond or outside it is clipped out.

Note: Masking is beyond the scope of this article, but CSS-Tricks2 and HTML5 Rocks3 have more information.

Below is a simple visualization of how clip-path works:

See the Pen Visualizing clip-path4 by Karen Menezes (@imohkay5) on CodePen6.

Note: The demos in this article, including the one above, will work in Firefox and in WebKit and Blink browsers, including Chrome, Safari and Opera.

Clip-Path Is Not Clip

There is an older CSS 2.1 clip property7, which is rather restrictive, notably because it supports only rectangular shapes. It has been deprecated in favor of clip-path8.

Articles about clipping that use the deprecated syntax feature code that looks like this:

.element 
  clip: rect(30px, 30px, 20px, 20px);

Support For Clip-Path

In August 2014, the “CSS Masking Module” was published as a “Candidate Recommendation,” which is a step up from the earlier “Last Call Working Draft” stage. Before we look at browser support, it’s important to consider the multiple ways in which clip-path can be applied to an element, because browser support varies for each method.

There are two ways to use clip-path:

  1. with CSS
    Basic shapes from the “CSS Shapes Module9” provide a convenient way to use clip-path. The different shapes available are polygon, circle, ellipse and inset; inset is for rectangular shapes.
  2. with SVG
    One can, alternatively, create a shape using SVG and then clip an element to this shape via the URL syntax. There are two ways to do this:

    • with a reference to an inline SVG (i.e. the SVG markup exists on the page itself),
    • with a reference to an external SVG document.

    In both cases, the clipPath element within the SVG is used to wrap the element that determines the clipping path, be it a circle, polygon, path or other element. Compare the demo below in Firefox and in a WebKit or Blink browser such as Chrome to spot the differences. Square images imply a lack of browser support.

    Note: The third image does not show up in Safari. Despite extensive debugging, I’m unable to resolve the issue. I’d appreciate a note in the comments section if you come across the solution.

See the Pen Clip-path: Browser support10 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

As you may have gathered from observing the demo above in different browsers, support for clipping paths13 is quirky and currently depends on the means by which you choose to clip an element:

  • with CSS: Chrome 24+, Safari 7+, Opera 15+, iOS 7.1+, Android 4.4+, Opera Mobile 24+
    (Note that all supported browsers currently require the -webkit vendor prefix.)
  • with SVG: all of the browsers listed above and Firefox 3.5+

The clip-path property is not yet supported in Internet Explorer but is currently under consideration14 as part of the “Masking Module.”

Note: There is a caveat with support for SVG clipping path. Modern WebKit and Blink browsers support clipping paths with SVGs only if they are declared inline (i.e. within the document). References to external SVGs are supported only in Firefox, as evidenced in the demo above. The Chromium project is tracking this bug15.

Let’s examine the advantages of CSS versus SVG with clip-path.

Advantages of CSS

  • The lucid syntax is easy to grasp due to the relative simplicity of basic shapes.
  • Responsiveness is easily achieved with relative units, such as percentages.

Advantages of SVG

  • Browser support is better, with the addition of Firefox.
  • You can clip with complex shapes, multiple shapes and text.

While CSS offers a background-clip property that provides us with some options (including a non-standard way to clip text), neither background-clip nor CSS’ clip-path match what SVG clipping can achieve in modern browsers. Getting acquainted with clip-path via CSS, however, is less intimidating (especially if you aren’t familiar with manipulating SVGs) and will prepare you for the intricacies of clipping paths with SVG, as well as the “CSS Shapes Module16,” where content aligns itself to the shape of an element.

Note: If you can’t wait to delve into the matrix of clipping with SVG, Sara Soueidan’s overview17 is a good starting point.

Let’s look at the pros and cons of using clip-path to progressively enhance our designs.

Pros

  • Browsers that don’t support the clip-path property will ignore it. If you use it with care, users on non-supporting browsers won’t suspect a thing!
  • Once a clipping-path shape is generated, the specification states that pointer events must not be dispatched outside the clipping area (which is ideal). So, the click event is restricted to the shape and its outer boundary18. We will look at this in the demos below.
  • You can use percentages or any length unit, such as pixels or ems, to define your coordinates with basic shapes using CSS. Fluid units such as percentages can be used to create responsive shapes, perfect for adaptive layouts.

Cons

  • All borders, shadows and outlines outside the clipping region will be clipped19. You can’t add a border and expect it to be honored. We’ll look at some alternatives below.
  • The specification has not yet reached the “Recommendation” stage, so there’s always a chance that the syntax will change in the interim.
  • A few bugs have been reported with clip-path and 3D transforms, transitions and opacity, which are covered in the demos below. Be aware of these, and avoid combining properties that replicate these bugs.

Clip-Path With Polygons: Usage And Syntax

The demos below focus on using different kinds of polygons in a design. The syntax for the other basic shapes (i.e. inset, circle and ellipse) is quite simple, and you can go only so far with them. Polygons, however, open the door to a practically infinite numbers of shapes.

The syntax for a basic polygon shape is this:

.element  clip-path: polygon(x1 y1, x2 y2, x3 y3, ...); 

Each argument pair in the list represents the x-axis and y-axis coordinates of that particular vertex of the polygon.

Here’s how we’d write it in the real world (minus the currently supported WebKit-prefixed version):

.element  clip-path: polygon(0 100%, 0 0, 100% 0, 80% 100%); 

Let’s add support for Firefox with a reference to an inline SVG:

.element  clip-path: url("#clip-shape"); 

Here’s how our selector will finally look, with cross-browser support:

.element 
  -webkit-clip-path: polygon(0 100%, 0 0, 100% 0, 80% 100%);
  clip-path: polygon(0 100%, 0 0, 100% 0, 80% 100%);
  -webkit-clip-path: url("#clip-shape"); /* required for Webkit/Blink browsers if you're using only inline SVG clipping paths, but not CSS clip-path */
  clip-path: url("#clip-shape");

Below is the code for the inline SVG, which we will need to insert anywhere in the markup.

<svg width="0" height="0">
  <defs>
	<clipPath id="clip-shape" clipPathUnits="objectBoundingBox">
	  <polygon points="0 1, 0 0, 1 0, 0.8 1" />
	</clipPath>
  </defs>
</svg>

Here is the final demo.

See the Pen Clip-path: Demo20 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

You can create a responsive SVG clipping path in the following manner:

  • Set the width and height of the SVG to 0.
  • Set an ID on the clipPath element inside the SVG, which can then be referenced with CSS. You can use inline or external SVG, keeping in mind the browser support mentioned above.
  • Reuse the percentage coordinate values of the polygon defined with CSS clip-path. Just divide them by 100 and add as unitless polygon points to the SVG.
  • Set the value of the clipPathUnits attribute to objectBoundingBox, so that the clipping path honors the boundaries of the HTML element that references it.

Dudley Storey has more23 on this process.

Let’s look at a demo to understand how to plot coordinates for a polygon.

Below we have an image that is clipped. The background color represents the dimensions of the original image. The black boxes with the coordinates are simply absolutely positioned divs whose locations match the polygon’s vertices in percentages. You will see that they maintain their positions, even if you resize your browser window to a narrow width (for example, 400 pixels or greater).

See the Pen Clip-path: Polygon coordinates24 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

Real-World Examples With Clip-Path

Note: Every demo in this article uses clip-path with CSS but also has inline SVG in the markup with a class of clip-svg, which simply resets the width and height of the SVG to 0. You could, alternatively, remove the class and set the width and height attributes directly in the SVG markup.

Example 1: Clip An Image to Various Polygon Shapes

In case you need a quick definition of a polygon, it’s a 2D shape that’s closed and consists of straight lines.

Therefore, a shape cannot be a polygon if it has curves, is open or has fewer than three lines. Some famous polygons in history are triangles, quadrilaterals, pentagons and hexagons. Even star shapes are polygons, since the boundaries of a polygon can cross each other.

Note: The images in the demo are responsive. By using the good ol’ responsive image solution of img max-width: 100%; height: auto; and adaptive clipping paths via CSS and SVG, we make our polygons blissfully scale up and down.

This demo is the result of an exercise to understand plotting coordinates to make polygon shapes. I’ve added several shapes that you can use for your designs in the demo below. On hovering over each image, you will see the aspect ratio of the original image.

Nothing beats the exceptional Clippy7727, a GUI tool by Bennett Feely to visualize shapes. All coordinates for all of the existing shapes are provided in percentages, and there’s also a custom polygon option. This one’s a game-changer. You can use Clippy to generate clipped shapes and create SVGs for yourself based on them, for better browser support.

See the Pen Clip-path: Polygon shapes28 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

Example 2: Animate a Basic Shape With CSS Transition

Hover over the purple hexagon. It transforms to an octagon. However, the CSS transition specified has not taken effect.

See the Pen Clip-path: shape transition: Part 131 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

The reason for this is explained in Sara Soueidan’s article on animating CSS shapes34: “The number of points defining the final shape must be the same as the number of points defining the initial shape.” Makes perfect sense!

Because a hexagon has six pairs of coordinate points, let’s add two pairs through duplication to make them eight, to match the number of pairs for an octagon. These duplicated pairs won’t affect the shape of the hexagon.

This is the declaration for a hexagon in the form of a default polygon with six pairs of coordinate points:

clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);

And this is the declaration for a hexagon in the form of a polygon with eight pairs of coordinates, the first two of which have been duplicated:

clip-path: polygon(50% 0%, 50% 0%, 100% 25%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);

Now the transition will be smooth as the shapes transform, as seen in the demo below.

Note: For browsers that support clipping paths only with SVG (currently Firefox), we need to add a SMIL animation to obtain a seamless transition on hover. According to the SMIL specification, declarative animations can be used to animate paths and polygon points in SVG, which is currently impossible with CSS.

Keep in mind that some people are discussing deprecating SMIL in Chrome and Chromium35 and focusing on implementing the Web Animations API36, which is unfortunately at the early draft stage.

In the demo below (background image courtesy of morgueFile37), you can see that we have animated the polygon points between the mouseover and mouseout events over a duration of 0.2 seconds. Look for the <animate> tag in the SVG markup.

See the Pen Clip-path: shape transition: Part 238 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

Example 3: Add a Border to a Clipped Object

To make a long story short, borders, outlines and box-shadows that lie outside the clipping region are removed.

I was a little saddened by this, and I pinged the W3C members on the working group for CSS. However, the conclusion is that there’s no way to do this when you’re using basic shapes. Dirk Schulze41 responded to my query: “Yes, all drawing operations belonging to the element get clipped. This includes outlines and borders.”

See the demo below. Hover over the rhomboid with a partial border to see the original, unclipped version with the entire border.

See the Pen Clip-path: Borders42 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

Of course, we can always use a CSS hack to get a border, which is what I finally resorted to — good ol’ generated content.

The demo below creates a copy of the element via a pseudo-element (content:after) and absolutely positions it. This creates the illusion of a border, enabling us to simulate interesting effects, such as the gradient border seen in the second octagon and the inset box-shadow via a CSS filter on the third one (not very pretty, but functional). Note that CSS filters currently work only in Firefox and in WebKit and Blink browsers.

See the Pen Clip-path: Border simulation45 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

Example 4: Use clip-path to Create a Diamond Grid Over a Rhombus

Below is the image we will use.

clip-image-demo48
(View large version49)

This is the effect we’re aiming for. Upon hovering over the bottom three boxes, you’ll see the background color fade to reveal the background.

demo-clip-diamond50
(View large version51)

The actual size of the image is 600 × 600 pixels. Thus, let’s start with four empty divs of 300 pixels each and apply the same background image to them. Let’s add a parent wrapper of 604 pixels and lay out the images with the inline-block property.

demo-clip-diamond152
(View large version53)

Let’s now change the value of the background-position property for each image to top, left, right and bottom, respectively.

demo-clip-diamond254
(View large preview55)

Let’s clip each box into the shape of a rhombus. We will overlay an absolutely positioned layer on each of the bottom three images, with some text.

demo-clip-diamond356
(View large version57)

Now we will move the images into rows — the second and third image into one row, and the first and fourth into their own individual rows.

demo-clip-diamond458
(View large version59)

Finally, we will use negative margins to push up the second and third rows, so that they are laid out as in the final demo below. We can remove the width value of 604 pixels on the parent wrapper, and we can structure our media query so that the four diamond boxes move from a stacked layout on small screens to inline blocks on larger ones.

See the Pen Clip-path: Diamond grid60 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

While working on this demo, I noticed a bug in Chrome with pointer events being dispatched outside the clipped region, which violates the specification63: “By default, pointer events must not be dispatched on the clipped-out (non-visible) regions of a shape.” I have filed the bug64. The issue with this demo was solved by using the pointer-events property with a value of none on the overlay. Alternatively, you could apply the same clip-path value to the overlay to resolve the issue.

Due to the negative margins applied, this demo would look odd in browsers that don’t support clip-path. You would have to use some sort of feature detection to apply the margins (although I haven’t experimented with this) or the @supports CSS feature query, although I wouldn’t recommend the latter in production code.

Example 5: Create a Dummy Profile Page With Hexagons

Our final page should look like this:

hexagon-demo65
(View large version66)

We’ll start by adding a background image of hexagon tiles to the body (the image courtesy of Subtle Patterns67).

The hexagon clip-path values can be obtained from one of the demos above or with the Clippy tool.

The first hexagon uses a background image (because we’re blending a dull maroon into the background using the background-blend-mode property). Using generated content, an absolutely positioned overlay is clipped to a maroon triangle shape, which you can see on the bottom. It disappears on hover.

The second hexagon, with the word “work,” simply has a dark grey background that changes on hover.

The third hexagon has a gradient border, similar to the one in the demo on creating borders with clip-path.

The hexagons stack on small screens and are vertically centered on larger ones. I’ve used a combination of display: table and the absolute centering transforms hack — of course, you could use flexbox, floats or whatever else floats your layouting boat.

Here’s the final demo.

See the Pen Clip-path: Hexagon shapes for dummy profile page68 by Karen Menezes (@imohkay69614643393229252111) on CodePen70624744403330262212.

I discovered a bug71 with clip-path while creating this demo. Altering the value of opacity in combination with the CSS transition causes a flicker and artifacts on the page. Be aware of this if you’re using clip-path to progressively enhance a design.

There is also a bug with clip-path and the backface-visibility property when set to hidden. This bug is documented in Chromium72’s issue tracker and I have been able to replicate it using the basic shape syntax in Chrome on Linux. Keep this in mind if you’re using a clip-path shape to do a cool 3D flip or anything that uses CSS 3D transforms.

While clipping with SVG wins hands down for its flexibility and options, nothing beats the ease with which elements can be clipped with CSS. In fact, the same polygon coordinates can be effortlessly recycled to create responsive SVG for even better browser support. With clip-path, you can dramatically alter the look and feel of a page, without having to worry much about non-supporting browsers, where it will gracefully degrade. If you choose to use clip-path for design enhancements, keep an eye on the specification as it advances towards “Recommendation” status.

Resources, Tools And Inspiration

  • CSS Masking Module Level 1731,” W3C
    This is the ultimate source of truth and the best reference, when in doubt.
  • Clipping in CSS and SVG: The clip-path Property and <clipPath> Element74,” Sara Soueidan
    Soueidan has the definitive guide to clipping paths. While the focus is largely on SVG, this article is a fantastic introduction, with plenty of information for both intermediate and advanced readers.
  • clip-path75,” Sara Soueidan, Codrops
    Soueidan’s well-researched and comprehensive article over on Codrops breaks down a fairly complicated module into something that is easy to understand and assimilate.
  • Clipping and Masking in CSS76,” Chris Coyier, CSS-Tricks
    Coyier’s article, peppered with several helpful demos, explains both clipping and masking.
  • Clippy7727
    Bennett Feely’s fab clip-path maker can generate a plethora of predefined and custom polygon shapes, circles and ellipses for CSS’ clip-path. All values are in percentages and, hence, useful for responsive layouts.
  • Clip Path Generator78
    CSS Plant offers a rather comprehensive graphical interface to clip or mask an element. Cross-browser support is provided for Firefox, Chrome, Safari and old iOS. Clips are in pixels, not percentages.
  • Species in Pieces79
    So breathtaking it borders on the spiritual, this showcase of 30 endangered species was crafted entirely with CSS’ clip-path, without a hint of canvas or WebGL. View it in a WebKit or Blink browser until the other ones catch up.

(ds, il, al)

Footnotes

  1. 1 http://www.w3.org/TR/css-masking-1
  2. 2 http://css-tricks.com/clipping-masking-css
  3. 3 http://www.html5rocks.com/en/tutorials/masking/adobe/
  4. 4 http://codepen.io/imohkay/pen/KpdomO/
  5. 5 http://codepen.io/imohkay
  6. 6 http://codepen.io
  7. 7 http://www.w3.org/TR/CSS21/visufx.html#clipping
  8. 8 http://www.w3.org/TR/css-masking-1/#clip-property
  9. 9 http://www.w3.org/TR/css-shapes-1/#typedef-basic-shape
  10. 10 ‘http://codepen.io/imohkay/pen/GJpxXY/’
  11. 11 ‘http://codepen.io/imohkay’
  12. 12 ‘http://codepen.io’
  13. 13 http://caniuse.com/#search=clip-path
  14. 14 https://status.modern.ie/masks?term=masks
  15. 15 https://code.google.com/p/chromium/issues/detail?id=109212
  16. 16 http://www.w3.org/TR/css-shapes/
  17. 17 http://sarasoueidan.com/blog/css-svg-clipping/
  18. 18 http://www.w3.org/TR/css-masking-1/#clipping-paths
  19. 19 http://www.w3.org/TR/css-masking-1/#clipping-paths
  20. 20 ‘http://codepen.io/imohkay/pen/pJjVob/’
  21. 21 ‘http://codepen.io/imohkay’
  22. 22 ‘http://codepen.io’
  23. 23 http://demosthenes.info/blog/1007/Combining-CSS-clip-path-and-Shapes-for-New-Layout-Possibilities
  24. 24 ‘http://codepen.io/imohkay/pen/pJjVgE/’
  25. 25 ‘http://codepen.io/imohkay’
  26. 26 ‘http://codepen.io’
  27. 27 http://bennettfeely.com/clippy
  28. 28 ‘http://codepen.io/imohkay/pen/RPWyjz/’
  29. 29 ‘http://codepen.io/imohkay’
  30. 30 ‘http://codepen.io’
  31. 31 ‘http://codepen.io/imohkay/pen/ZGbjbz/’
  32. 32 ‘http://codepen.io/imohkay’
  33. 33 ‘http://codepen.io’
  34. 34 http://sarasoueidan.com/blog/animating-css-shapes/
  35. 35 https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/5o0yiO440LM
  36. 36 http://www.w3.org/TR/web-animations/
  37. 37 http://www.morguefile.com/archive/display/946871
  38. 38 ‘http://codepen.io/imohkay/pen/ZGbjyG/’
  39. 39 ‘http://codepen.io/imohkay’
  40. 40 ‘http://codepen.io’
  41. 41 http://blog.dschulze.com
  42. 42 ‘http://codepen.io/imohkay/pen/zGvLjo/’
  43. 43 ‘http://codepen.io/imohkay’
  44. 44 ‘http://codepen.io’
  45. 45 ‘http://codepen.io/imohkay/pen/MwaBBK/’
  46. 46 ‘http://codepen.io/imohkay’
  47. 47 ‘http://codepen.io’
  48. 48 http://www.smashingmagazine.com/wp-content/uploads/2015/05/clip-img-large-preview-opt.jpg
  49. 49 http://www.smashingmagazine.com/wp-content/uploads/2015/05/clip-img-large-preview-opt.jpg
  50. 50 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond-demo-large-preview-opt.jpg
  51. 51 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond-demo-large-preview-opt.jpg
  52. 52 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond1-large-preview-opt.jpg
  53. 53 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond1-large-preview-opt.jpg
  54. 54 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond2-large-preview-opt.jpg
  55. 55 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond2-large-preview-opt.jpg
  56. 56 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond3-large-preview-opt.jpg
  57. 57 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond3-large-preview-opt.jpg
  58. 58 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond4-large-preview-opt.jpg
  59. 59 http://www.smashingmagazine.com/wp-content/uploads/2015/05/diamond4-large-preview-opt.jpg
  60. 60 ‘http://codepen.io/imohkay/pen/KpdBrw/’
  61. 61 ‘http://codepen.io/imohkay’
  62. 62 ‘http://codepen.io’
  63. 63 http://www.w3.org/TR/css-masking-1/#clipping-paths
  64. 64 https://code.google.com/p/chromium/issues/detail?id=468613
  65. 65 http://www.smashingmagazine.com/wp-content/uploads/2015/05/hexagons-demo-large-preview-opt.jpg
  66. 66 http://www.smashingmagazine.com/wp-content/uploads/2015/05/hexagons-demo-large-preview-opt.jpg
  67. 67 http://subtlepatterns.com
  68. 68 ‘http://codepen.io/imohkay/pen/ZGbmoQ/’
  69. 69 ‘http://codepen.io/imohkay’
  70. 70 ‘http://codepen.io’
  71. 71 https://code.google.com/p/chromium/issues/detail?id=446901
  72. 72 https://code.google.com/p/chromium/issues/detail?id=350724
  73. 73 http://www.w3.org/TR/css-masking-1
  74. 74 http://sarasoueidan.com/blog/css-svg-clipping
  75. 75 http://tympanus.net/codrops/css_reference/clip-path
  76. 76 http://css-tricks.com/clipping-masking-css/
  77. 77 http://bennettfeely.com/clippy
  78. 78 http://cssplant.com/clip-path-generator
  79. 79 http://www.species-in-pieces.com

The post Creating Responsive Shapes With Clip-Path And Breaking Out Of The Box appeared first on Smashing Magazine.

More here:

Creating Responsive Shapes With Clip-Path And Breaking Out Of The Box