{"id":3410,"date":"2024-02-26T07:30:06","date_gmt":"2024-02-26T07:30:06","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/create-custom-magento-2-theme\/"},"modified":"2025-03-17T05:13:12","modified_gmt":"2025-03-17T05:13:12","slug":"create-custom-magento-2-theme","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/create-custom-magento-2-theme\/","title":{"rendered":"How to Create a Custom Theme in Magento 2?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Want to get started with a custom Magento 2 theme development? Learn here the step-wise method.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Magento 2 is an ideal e-commerce platform for brands looking for high-end customizations. It allows brands to create e-stores that match their visual branding and offer experiences that match their brand values. By default, it offers a Luma theme and a blank theme (as a base for custom theme development.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Businesses can use the default Luma theme in production, but ideally, most businesses choose to develop a custom theme. And that\u2019s why learning how to create a custom Magento 2 theme can be important for you as a developer.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-create-a-custom-magento-2-theme\">Why Create a Custom Magento 2 Theme?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Custom Magento 2 theme development is crucial for several reasons. It helps the e-commerce business:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a design that matches the brand\u2019s identity<\/li>\n\n\n\n<li>Improve the website\u2019s search engine-friendliness<\/li>\n\n\n\n<li>Deliver experiences that match brand ethics<\/li>\n\n\n\n<li>Make the site stand out from others<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Overall, custom Magento 2 theme development is essential to creating an online store on the platform. Also when creating a custom theme in Magento 2, adding unique visual elements can make your store stand out, especially during seasonal events. For example, <a href=\"https:\/\/meetanshi.com\/blog\/add-snowfall-effects-to-magento-2\/\">snowfall effect in Magento store<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"custom-magento-2-theme-development-prerequisities\">Custom Magento 2 Theme Development: Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ideally, Magento 2 custom theme development requires you to have:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Experience in Magento 2 development<\/li>\n\n\n\n<li>Knowledge of UX fundamentals<\/li>\n\n\n\n<li>Magento instance in a local environment<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s get started with the Magento custom theme development tutorial.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-create-a-custom-magento-2-theme\">How to Create a Custom Magento 2 Theme?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Magento does not recommend modifying the default theme code. The&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/how-to-upgrade-magento-2-to-latest-version\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento version upgrade<\/a>&nbsp;may override these changes. Instead, it is recommended to create a new theme.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Follow the steps below to create a custom Magento 2 theme.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"create-a-theme-dreictory\">Step 1: Create a Theme Directory<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">You need to create a new directory for the custom Magento 2 theme.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go to the&nbsp;<strong>[root_directory]\/app\/design\/frontend<\/strong><\/li>\n\n\n\n<li>Create a new folder with the vendor name, for e.g.,&nbsp;<strong>Meetanshi<\/strong><\/li>\n\n\n\n<li>Inside the vendor folder, create another folder with the theme name, for e.g.&nbsp;<strong>MitTheme<\/strong><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s what the Magento 2 custom theme directory will look like:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">app\/design\/frontend\/<br>\u251c\u2500\u2500 Meetanshi\/<br>\u2502 \u2502 \u251c\u2500\u2500MitTheme\/<br>\u2502 \u2502 \u2502 \u251c\u2500\u2500 &#8230;<br>\u2502 \u2502 \u2502 \u251c\u2500\u2500 &#8230;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"declare-magento-theme\">Step 2: Declare Magento Theme<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now, you need to declare a new theme so Magento 2 can find it. To do that, create a&nbsp;<code>theme.xml<\/code>&nbsp;file in the&nbsp;<strong>[root_directory]\/app\/design\/frontend\/Meetanshi\/MitTheme<\/strong>&nbsp;with the following code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;theme xmlns_xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi_noNamespaceSchemaLocation=\"urn:magento:framework:Config\/etc\/theme.xsd\">\n&lt;title>Meetanshi MitTheme&lt;\/title>\n&lt;parent>Magento\/Luma&lt;\/parent>\n&lt;media>\n&lt;preview_image>media\/MitTheme-image.jpg&lt;\/preview_image>\n&lt;\/media>\n&lt;\/theme><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the above code, we\u2019ve specified the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Title:<\/strong>&nbsp;Name of the custom theme<\/li>\n\n\n\n<li><strong>Parent:<\/strong>&nbsp;Theme for fallback purpose<\/li>\n\n\n\n<li><strong>Preview Image:<\/strong>&nbsp;Location of thumbnail image for the custom Magento 2 theme<\/li>\n<\/ul>\n\n\n\n<p class=\"has-background wp-block-paragraph\" style=\"background-color:#feefea\"><strong>Please note:<\/strong>&nbsp;In the above example, the preview image, i.e. MitTheme-image.jpg is located in the&nbsp;<strong>app\/design\/frontend\/Meetanshi\/MitTheme\/media\/<\/strong>&nbsp;directory. You will need to upload the preview image to the media directory before specifying it in the theme declaration.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"add-composer-package\">Step 3: Add Composer Package<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a composer.json file to declare the libraries that your custom Magento 2 theme depends on. This is important to distribute your theme as a package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s an example of&nbsp;<code>composer.json<\/code>&nbsp;file:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n    \"name\": \"Meetanshi\/MitTheme\",\n    \"description\": \"N\/A\",\n    \"require\": {\n        \"php\": \"~5.5.0|~5.6.0|~7.0.0\",\n        \"magento\/theme-frontend-blank\": \"100.0.*\",\n        \"magento\/framework\": \"100.0.*\"\n    },\n    \"type\": \"magento2-theme\",\n    \"version\": \"100.0.1\",\n    \"license\": [\n        \"OSL-3.0\",\n        \"AFL-3.0\"\n    ],\n    \"autoload\": {\n        \"files\": [\n            \"registration.php\"\n        ]\n    }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"add-registration-php-file\">Step 4: Add Registration.php File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Next, create a registration.php file for the custom theme. Navigate to the&nbsp;<strong>app\/design\/frontend\/Meetanshi\/MitTheme<\/strong>&nbsp;and create a&nbsp;<code>registration.php<\/code>&nbsp;file with the following code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/**\n* Copyright \u00a9 Magento. All rights reserved.\n* See COPYING.txt for license details.\n*\/\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n\\Magento\\Framework\\Component\\ComponentRegistrar::THEME,\n'frontend\/Meetanshi\/MitTheme',\n__DIR__\n);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-custom-theme\">Step 5: Configure Custom Theme<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once you\u2019ve declared the custom Magento 2 theme, you can configure it from the admin panel. Go to&nbsp;<strong>Stores &gt; Configuration &gt; Design<\/strong>&nbsp;and select the custom theme you created. For e.g.,&nbsp;<code>MitTheme<\/code>&nbsp;in our case.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2024\/02\/Magento-2-custom-theme-set.png\" alt=\"Magento 2 custom theme\" class=\"wp-image-43718\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Click the \u201c<strong>Save Config<\/strong>\u201d button to apply changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And flush Magento 2 cache from the&nbsp;<strong>System &gt; Cache Management<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-image-properties\">Step 6: Configure Image Properties<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To configure the image sizes on the frontend pages like product grids, you need to configure the&nbsp;<code>view.xml<\/code>&nbsp;file. Copy the view.xml file of the parent theme into \/app\/design\/frontend\/Meetanshi\/MitTheme\/etc\/ directory and modify it to change the image sizes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For e.g., you can modify the following snippet to change the dimensions of the category grid images;<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">...\n  &lt;image id=\"category_page_grid\" type=\"small_image\">\n      &lt;width>550&lt;\/width>\n      &lt;height>550&lt;\/height>\n  &lt;\/image>\n...><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"declare-logo-in-custom-theme\">Step 7: Declare Logo in Custom Theme<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">To add a logo for your theme, you need to create a layout directory and define it. Navigate to&nbsp;<strong>\/app\/design\/frontend\/Meetanshi\/MitTheme\/Magento_Theme\/layout\/<\/strong>&nbsp;and create&nbsp;<code>default.xml<\/code>&nbsp;with the following code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;page xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:framework:View\/Layout\/etc\/page_configuration.xsd\">\n&lt;body>\n&lt;referenceBlock name=\"logo\">\n&lt;arguments>\n&lt;argument name=\"logo_file\" xsi:type=\"string\">images\/logo.png&lt;\/argument>\n&lt;argument name=\"logo_img_width\" xsi:type=\"number\">350&lt;\/argument>\n&lt;argument name=\"logo_img_height\" xsi:type=\"number\">350&lt;\/argument>\n&lt;\/arguments>\n&lt;\/referenceBlock>\n&lt;\/body>\n&lt;\/page><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"basic-layout-elements\">Step 8: Add Basic Layout Elements<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Magento pages are made up of containers and blocks. The containers contain the elements that appear on the page. For e.g., there are containers for the header, footer, etc.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"add-layout-files\">Step 9: Define Layout Files Types &amp; Conventions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The Magento 2 pages are rendered according to the layout files defined. Here are the basic conventional locations for different types of layouts:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Base layouts: Layout files provided by modules. Conventional location:\n<ul class=\"wp-block-list\">\n<li>Page configuration and generic layout files:&nbsp;<strong>\/view\/frontend\/layout<\/strong><\/li>\n\n\n\n<li>Page layout files:&nbsp;<strong>\/view\/frontend\/page_layout<\/strong><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Theme layouts: Layout files provided by themes. Conventional location:\n<ul class=\"wp-block-list\">\n<li>Page configuration and generic layout files:&nbsp;<strong>\/_\/layout<\/strong><\/li>\n\n\n\n<li>Page layout files:&nbsp;<strong>\/_\/page_layout<\/strong><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">But it is recommended to create a child Magento theme on top of the default Luma or Blank theme. That\u2019s because it can be overwhelming to define the custom Magento 2 layouts and elements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can utilize the child-parent theme relationship in Magento 2 and start customizing the base theme. You can always hire our Magento customization experts to get any help with custom theme development. You can customize your theme by <a href=\"https:\/\/meetanshi.com\/blog\/how-to-add-sticky-add-to-cart-to-magento-2\/\">adding sticky add to cart<\/a> button to serve better user experience, without letting users browsing journey getting disturbed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Want to get started with a custom Magento 2 theme development? Learn here the step-wise method. Magento 2 is an ideal e-commerce platform for brands&#8230;<\/p>\n","protected":false},"author":51,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-3410","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3410","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/51"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=3410"}],"version-history":[{"count":2,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3410\/revisions"}],"predecessor-version":[{"id":9291,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/3410\/revisions\/9291"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=3410"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=3410"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=3410"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}