{"id":27811,"date":"2016-08-25T21:01:37","date_gmt":"2016-08-25T13:01:37","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=27811"},"modified":"2018-04-09T16:57:41","modified_gmt":"2018-04-09T08:57:41","slug":"css-image-zoom-onclick","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/","title":{"rendered":"How to Create Pure CSS onClick Image Zoom Effect"},"content":{"rendered":"<p>CSS doesn\u2019t have a pseudoclass for <strong>targeting click events<\/strong>, and this constitutes one of the <strong>biggest pain points<\/strong> of front-end developers. The closest pseudo-class is <code>:active<\/code> which styles an element for the period of time a user presses their mouse over it.<\/p>\n<p>This effect is however short-lived: once the user releases the mouse, <code>:active<\/code> doesn\u2019t work any more. We need to find some other way to <strong>emulate the click event in CSS<\/strong>.<\/p>\n<p>This post has been written in response to a <a href=\"https:\/\/www.hongkiat.com\/blog\/submit-news-tips\/\">reader\u2019s request<\/a>, and it\u2019s going to explain how to <strong>target the click event with pure CSS<\/strong> in a specific use case, <strong>image zoom<\/strong>.<\/p>\n<p>You can see the final result below \u2014 a CSS-only solution for <strong>image zoom on click<\/strong>.<\/p>\n<p class=\"recommended_top\">\n\t\t\t\t\t<strong>Read Also:<\/strong>\u00a0\n\t\t\t\t\t<a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/definite-guide-css-pseudoclasses\/\">Comprehensive Guide to CSS Pseudo-Classes and Their Usage<\/a>\n\t\t\t\t<\/p>\n<p><iframe height=\"514\" scrolling=\"no\" src=\"https:\/\/codepen.io\/rpsthecoder\/embed\/yJjYWm\/?height=514&theme-id=12825&default-tab=result&embed-version=2\" frameborder=\"no\" allowtransparency=\"true\" allowfullscreen=\"true\" style=\"width: 100%;\">See the Pen <a href=\"https:\/\/codepen.io\/rpsthecoder\/pen\/yJjYWm\/\" rel=\"nofollow\">Image Zoom (Pure CSS)<\/a> by Preethi (<a href=\"https:\/\/codepen.io\/rpsthecoder\" rel=\"nofollow\">@rpsthecoder<\/a>) on <a href=\"https:\/\/codepen.io\" rel=\"nofollow\">CodePen<\/a>. <\/iframe><\/p>\n<h2>When to Use the CSS-Only Solution<\/h2>\n<p>Before I proceed, I do want to say, that for image zoom I recommend the CSS-only method (which changes the dimensions of the image), only when you want a <strong>single<\/strong> or a <strong>group of few images<\/strong> to have the zoom feature.<\/p>\n<p>For a <em>proper<\/em> gallery, JavaScript provides more flexibility and efficiency.<\/p>\n<h2>Front-End Techniques We\u2019ll Use<\/h2>\n<p>Now that you\u2019ve been cautioned, let\u2019s quickly look over the <strong>3 key techniques<\/strong> we\u2019ll be using:<\/p>\n<ol>\n<li>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/map\" target=\"_blank\"><code>&lt;map&gt;<\/code><\/a><strong> HTML tag<\/strong> that allows browsers to <strong>create linkable areas over an image<\/strong>. Read more on the <code>&lt;map&gt;<\/code> element in my <a href=\"https:\/\/www.hongkiat.com\/blog\/cool-useful-html-tags\/\">earlier post<\/a>.<\/li>\n<li>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/img#attr-usemap\" target=\"_blank\"><code>usemap<\/code><\/a><strong> attribute of the <code>&lt;img&gt;<\/code> tag<\/strong>, that hooks up the image to the image map.<\/li>\n<li>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/:target\" target=\"_blank\"><code>:target<\/code><\/a><strong> CSS pseudo-class<\/strong> that represents an element that has been targeted using its ID selector.<\/li>\n<\/ol>\n<h3>1. Create the HTML Base<\/h3>\n<p>First, let\u2019s create the HTML base. In the code below, we add <strong>an image to be zoomed and expanded<\/strong> & <strong>close button icons<\/strong> for zooming in and out.<\/p>\n<pre>\r\n&lt;img id=\"img1\" class=\"img\" src=\"https:\/\/bitly.com\/2acrH5J\" \/&gt;\r\n&lt;a href=\"#\" class=\"close\"&gt;&lt;\/a&gt;\r\n&lt;img class=\"expand\" src=\"Expand-icon.png\" \/&gt;\r\n<\/pre>\n<p>It\u2019s important to have an ID on the image to be zoomed, and the Close button needs to be a link that has the <code>href=\"#\"<\/code> attribute, I\u2019ll explain why later in the post.<\/p>\n<h3>2. Add the CSS<\/h3>\n<p>Initially, the Close icon <strong>shouldn\u2019t be displayed<\/strong>. The <code>position<\/code>, <code>margin-<\/code>, <code>left<\/code>, and <code>bottom<\/code> properties <strong>place <\/strong>the<strong> Expand and Close icons<\/strong> where we want them to be \u2014 at the top-right corner of the image.<\/p>\n<p>The <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/pointer-events#values\" target=\"_blank\"><code>pointer-events: none;<\/code><\/a> rule allows mouse events to <strong>pass through the Expand icon<\/strong> and <strong>reach the image<\/strong>.<\/p>\n<pre>\r\n.img {\r\n  height: 150px;\r\n  width: 200px;\r\n}\r\n.close {\r\n  background-image: url(\"Close-icon.png\");\r\n  background-repeat: no-repeat;\r\n  bottom: 418px;\r\n  display: none;\r\n  height: 32px;\r\n  left: 462px;\r\n  margin-top: -32px;\r\n  position: relative;\r\n  width: 32px;\r\n}\r\n.expand {\r\n  bottom: 125px;\r\n  margin-left: -32px;\r\n  margin-right: 16px;\r\n  pointer-events: none;\r\n  position: relative;\r\n}\r\n<\/pre>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-out.jpg\" width=\"700\" height=\"318\" alt=\"Image with Expand Button\"><figcaption>Initial state with visible Expand and hidden Close icons<\/figcaption><\/figure>\n<h3>3. Add the Image Map<\/h3>\n<p>On the image map, the <strong>clickable area<\/strong> should be <strong>at the top-right corner<\/strong> of the image right below the Expand icon, and about its size. Place the <code>&lt;map&gt;<\/code> element before the first <code>&lt;img&gt;<\/code> tag in the HTML. We\u2019ll bind the image to the map in the next step.<\/p>\n<pre>\r\n&lt;map name=\"m1\"&gt;\r\n  &lt;area shape=\"rect\" coords=\"170 5 195 30\" href=\"#img1\"&gt;\r\n&lt;\/map&gt;\r\n<\/pre>\n<p>In the code block above, the <a href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/HTML\/Element\/area\" target=\"_blank\"><code>&lt;area&gt;<\/code><\/a> tag defines the <strong>shape, size, and URI of a linkable area<\/strong> inside an image map. For a <strong>rectangular shape<\/strong>, the <code>shape<\/code> attribute takes the <code>rect<\/code> value, and the <strong>four values <\/strong>of the <code>coords<\/code> attribute represent the distance in pixels between:<\/p>\n<ol>\n<li>the left edge of the image & the left edge of the link area<\/li>\n<li>the top edge of the image & the top edge of the link area<\/li>\n<li>the left edge of the image & the right edge of the link area<\/li>\n<li>the top edge of the image & the bottom edge of the link area<\/li>\n<\/ol>\n<p>The value of the <code>href<\/code> attribute has to be the <strong>hash identifier of the image<\/strong> (this is why the image should have an <code>id<\/code>).<\/p>\n<h3>4. Bind the image to the Image Map<\/h3>\n<p>Add the <a href=\"https:\/\/www.w3schools.com\/tags\/att_img_usemap.asp\" target=\"_blank\"><code>usemap<\/code><\/a> attribute to the image so as to <strong>bind it to the image map<\/strong>. Its value needs to be the <strong>hash representation of the <code>name<\/code> attribute of the <code>&lt;map&gt;<\/code> tag<\/strong> we added in Step 3.<\/p>\n<pre>\r\n&lt;img id=\"img1\" class=\"img\" usemap=\"#m1\"\r\n    src=\"https:\/\/bitly.com\/2acrH5J\" \/&gt;\r\n<\/pre>\n<p>The clickable area of the image map now <strong>lies behind the Expand button<\/strong>. When the user clicks the Expand button, it\u2019s the clickable area that is clicked in reality \u2014 remember that we made the Expand button \u201cpassable\u201d with the <code>pointer-events: none;<\/code> rule in Step 2.<\/p>\n<p>This way the user <strong>targets the image itself<\/strong> by clicking it, and after the click the URI gets suffixed with the <code>\"#img1\"<\/code> <a href=\"https:\/\/www.w3.org\/DesignIssues\/Fragment.html\" target=\"_blank\" rel=\"nofollow\">fragment identifier<\/a>.<\/p>\n<h3>5. Style the <code>:target<\/code> Pseudo-Class<\/h3>\n<p>Until the <code>\"#img1\"<\/code> fragment identifier is at the end of URI, the targetted image can be <strong>styled with the <\/strong><code>:target<\/code><strong> pseudo-class<\/strong><\/p>\n<p>The dimensions of the targeted image increase, the Close button gets shown, and the Expand button gets hidden.<\/p>\n<pre>\r\n.img:target {\r\n    height: 450px;\r\n    width: 500px;\r\n}\r\n.img:target+.close {\r\n    display: block;\r\n}\r\n.img:target+.close+.expand {\r\n    display: none;\r\n}\r\n<\/pre>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-in.jpg\" width=\"700\" height=\"463\" alt=\"Zoomed Image with Visible Close Button\"><figcaption>Zoomed Image with Visible Close button<\/figcaption><\/figure>\n<h3>How the Close Button Works<\/h3>\n<p>As the Close button was added as a background image (Step 2), and is actually  an <code>&lt;a&gt;<\/code> tag with the <code>href=#<\/code> attribute (Step 1), when it\u2019s clicked, it removes the fragment identifier from the end of the URI. Therefore it also <strong>removes the <code>:target<\/code> pseudo-class<\/strong> from the image, and the image <strong>goes back to its previous size<\/strong>.<\/p>\n<p>Now the CSS-only zoom-on-click effect is done, check out the demo below, or read a little bit more on the theory behind image maps in the next section.<\/p>\n<p><iframe height=\"514\" scrolling=\"no\" src=\"https:\/\/codepen.io\/rpsthecoder\/embed\/yJjYWm\/?height=514&theme-id=12825&default-tab=result&embed-version=2\" frameborder=\"no\" allowtransparency=\"true\" allowfullscreen=\"true\" style=\"width: 100%;\">See the Pen <a href=\"https:\/\/codepen.io\/rpsthecoder\/pen\/yJjYWm\/\" rel=\"nofollow\">Image Zoom (Pure CSS)<\/a> by Preethi (<a href=\"https:\/\/codepen.io\/rpsthecoder\" rel=\"nofollow\">@rpsthecoder<\/a>) on <a href=\"https:\/\/codepen.io\" rel=\"nofollow\">CodePen<\/a>. <\/iframe><\/p>\n<h3>Background Info: Why <code>&lt;map&gt;<\/code> and not <code>&lt;a&gt;<\/code>?<\/h3>\n<p>By now, you certainly understand that the most important thing for this CSS-only solution to work is to <strong>target the image using the <\/strong><code>href=\"#imgid\"<\/code><strong> attribute<\/strong>, which could also be done using the <code>&lt;a&gt;<\/code> tag instead of the image map.<\/p>\n<p>This may be true, however when it comes to images, using the <code>&lt;map&gt;<\/code> element is more appropriate. It\u2019s even more important that when you want the zoom to <strong>happen on clicking on a larger area on the image<\/strong> rather than just on the Expand icon, <code>&lt;map&gt;<\/code> gives you an easy solution.<\/p>\n<pre>\r\n&lt;map name=\"m1\"&gt;&lt;area shape=\"default\" href=\"#img1\"&gt;&lt;\/map&gt;\r\n<\/pre>\n<p>The <code>default<\/code> value for <code>shape<\/code> attribute creates a <strong>rectangular linkable area that covers the whole image<\/strong>. If you were to use <code>&lt;a&gt;<\/code> instead, you would have to code it to cover the image, and you may also have to use a wrapper element for the same purpose.<\/p>\n<p>To also speak about the caveats of this solution, the <code>pointer-events<\/code> CSS property (we used in Step 2) is supported by Internet Explorer <strong><a href=\"https:\/\/caniuse.com\/#search=pointer-events\" target=\"_blank\">only from version 11<\/a><\/strong>.<\/p>\n<p>To support IE browsers before that, you may want to either use <code>&lt;a&gt;<\/code> instead of <code>&lt;map&gt;<\/code>, or have the image zoomed on by clicking anywhere on it (in this case there\u2019ll be no need for the Expand icon).<\/p>","protected":false},"excerpt":{"rendered":"<p>CSS doesn\u2019t have a pseudoclass for targeting click events, and this constitutes one of the biggest pain points of front-end developers. The closest pseudo-class is :active which styles an element for the period of time a user presses their mouse over it. This effect is however short-lived: once the user releases the mouse, :active doesn\u2019t&hellip;<\/p>\n","protected":false},"author":145,"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.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to Create Pure CSS onClick Image Zoom Effect - Hongkiat<\/title>\n<meta name=\"description\" content=\"CSS doesn&#039;t have a pseudoclass for targeting click events, and this constitutes one of the biggest pain points of front-end developers. The closest\" \/>\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\/css-image-zoom-onclick\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Pure CSS onClick Image Zoom Effect\" \/>\n<meta property=\"og:description\" content=\"CSS doesn&#039;t have a pseudoclass for targeting click events, and this constitutes one of the biggest pain points of front-end developers. The closest\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/\" \/>\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=\"2016-08-25T13:01:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-04-09T08:57:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-out.jpg\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"How to Create Pure CSS onClick Image Zoom Effect\",\"datePublished\":\"2016-08-25T13:01:37+00:00\",\"dateModified\":\"2018-04-09T08:57:41+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/\"},\"wordCount\":1005,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-image-zoom-onclick\\\/css-img-zoom-out.jpg\",\"keywords\":[\"CSS\",\"CSS Tutorials\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/\",\"name\":\"How to Create Pure CSS onClick Image Zoom Effect - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-image-zoom-onclick\\\/css-img-zoom-out.jpg\",\"datePublished\":\"2016-08-25T13:01:37+00:00\",\"dateModified\":\"2018-04-09T08:57:41+00:00\",\"description\":\"CSS doesn't have a pseudoclass for targeting click events, and this constitutes one of the biggest pain points of front-end developers. The closest\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-image-zoom-onclick\\\/css-img-zoom-out.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/css-image-zoom-onclick\\\/css-img-zoom-out.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/css-image-zoom-onclick\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Create Pure CSS onClick Image Zoom Effect\"}]},{\"@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\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to Create Pure CSS onClick Image Zoom Effect - Hongkiat","description":"CSS doesn't have a pseudoclass for targeting click events, and this constitutes one of the biggest pain points of front-end developers. The closest","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\/css-image-zoom-onclick\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Pure CSS onClick Image Zoom Effect","og_description":"CSS doesn't have a pseudoclass for targeting click events, and this constitutes one of the biggest pain points of front-end developers. The closest","og_url":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2016-08-25T13:01:37+00:00","article_modified_time":"2018-04-09T08:57:41+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-out.jpg","type":"","width":"","height":""}],"author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"How to Create Pure CSS onClick Image Zoom Effect","datePublished":"2016-08-25T13:01:37+00:00","dateModified":"2018-04-09T08:57:41+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/"},"wordCount":1005,"commentCount":3,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-out.jpg","keywords":["CSS","CSS Tutorials"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/","url":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/","name":"How to Create Pure CSS onClick Image Zoom Effect - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-out.jpg","datePublished":"2016-08-25T13:01:37+00:00","dateModified":"2018-04-09T08:57:41+00:00","description":"CSS doesn't have a pseudoclass for targeting click events, and this constitutes one of the biggest pain points of front-end developers. The closest","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-out.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/css-image-zoom-onclick\/css-img-zoom-out.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/css-image-zoom-onclick\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Pure CSS onClick Image Zoom Effect"}]},{"@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\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-7ez","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/27811","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\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=27811"}],"version-history":[{"count":2,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/27811\/revisions"}],"predecessor-version":[{"id":41886,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/27811\/revisions\/41886"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=27811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=27811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=27811"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=27811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}