# Storefront Web Components Storefront Web Components let you bring Shopify-powered commerce capabilities to any website. Display products, showcase collections, and offer a checkout, all with a few lines of embedded HTML. ## How Storefront Web Components work Storefront Web Components are a set of HTML components that handle the complexity of querying Shopify's Storefront API, letting you display products, collections, and shopping cart functionality on your website without having to write complex JavaScript code. After you add the `` and `` components to your markup and configure their attributes, you can access your store's data and then style it using CSS or HTML to create tailored shopping experiences. Storefront Web Components are built for a wide range of use cases, from embedding your products and collections within existing content to building new pages for your site. - [Full page](https://webcomponents.shopify.dev/playground?view=editor&preset=product-cards-discover): Collection page - [Full page](https://webcomponents.shopify.dev/playground?view=editor&preset=blog-post): Blog post - [Embedded](https://webcomponents.shopify.dev/playground?view=editor&preset=ready-product-card-first): Product card ## Resources Follow the step-by-step guide to add Storefront Web Components to your project or browse sample code with live previews in the playground. - [Learn more](https://shopify.dev/docs/api/storefront-web-components/getting-started/): Getting started guide - [Explore](https://webcomponents.shopify.dev/playground): Storefront Web Components playground ## References - [shopify-attr](https://shopify.dev/docs/api/storefront-web-components/attributes/shopify-attr.txt): Use the `shopify-attr` attribute to bind an attribute to data from Shopify. Anywhere within the template of a [shopify-context component](https://shopify.dev/docs/api/storefront-web-components/components/shopify-context), you can use the `shopify-attr--attribute-name` attribute to bind an attribute to data from Shopify. For example, `shopify-attr--href="product.onlineStoreUrl"` can be used to bind the `href` attribute to the `onlineStoreUrl` field on a product context. See the [playground](https://webcomponents.shopify.dev/playground) for more complete examples. - [shopify-cart](https://shopify.dev/docs/api/storefront-web-components/components/shopify-cart.txt): The cart component provides a mini shopping cart functionality for your website. Here's how it works: 1. Add a `button` component inside a [shopify-context component](https://shopify.dev/docs/api/storefront-web-components/components/shopify-context) that's associated with a product. 2. Call the `addLine()` method in the `button` component's `onclick` attribute to add the product to the customer's cart. - This method requires an event object or a product data object. - If using an event, the event target must be inside a product [context component](https://shopify.dev/docs/api/storefront-web-components/components/shopify-context). 3. Display the cart using a native [HTML `` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog). - To show it as a popup modal, call the `showModal()` method. 4. Apply discount codes automatically using the `discountCodes` attribute. - Pass a comma-separated list of discount codes that will be automatically applied to the cart. 5. Customize the cart's styling and content with CSS parts and slots. [View examples](https://shopify.dev/docs/api/storefront-web-components/components/shopify-cart#examples) > Note: > The cart component doesn't support mixing products from multiple stores. - [shopify-checkout](https://shopify.dev/docs/api/storefront-web-components/components/shopify-checkout.txt): > Caution: > This is in Developer Preview and the API is subject to change. The `shopify-checkout` component embeds Checkout on your website. When requested, the `shopify-checkout` component will open Checkout in a popup browser window over the current page, and will provide events for key buyer actions that happen during the checkout process. To use the component, create a `shopify-checkout` element, and set the `src` attribute to any valid checkout URL. This can be the `cart.checkoutUrl` field from the Storefront API, a cart permalink, or any other URL that would redirect to Checkout if loaded directly. Then, when you are ready to show checkout, call `open()`, which presents a popup window over the current page. It is best practice to use the checkout URL as the `href` for an `` element, and to progressively enhance clicks on this link into the `src` attribute and `open()` method call on `shopify-checkout`. This ensures that users can still navigate to Checkout, even if JavaScript is disabled or broken. The `shopify-checkout` component does not render any content by default, and only opens a popup window when `open()` is called. As a result, there are no slots or other style customization options available. - [shopify-context](https://shopify.dev/docs/api/storefront-web-components/components/shopify-context.txt): The context component defines which Shopify data should be available in different parts of your page. Each `` component requires two attributes: - `type`: Specifies what kind of data you want (for example, `product`). - `handle` or `gid`: Identifies the specific item. For example, the handle for the URL [`demostore.mock.shop/products/men-t-shirt`](https://demostore.mock.shop/products/men-t-shirt) is `men-t-shirt`. The `gid` attribute can be used to identify the item by its unique id, e.g. `gid://shopify/Product/7982853619734`. If you're working with a single storefront, then you can add the `` component anywhere on your page (it doesn't need to be inside the `` component). If you're working with multiple storefronts, then nest the context inside its corresponding store component. Every `` component also requires a `