Connect your page with Google Sheets - SheetDB - Google Sheets REST API

Connect any website with Google Spreadsheet using just HTML?

If you want to display something from Google Sheets at your website and you don't know how to code, the easiest solution is to use our handlebars library.

In this article we're gonna use this spreadsheet:

And this is url to our API:

To display the content, you need to add data-sheetdb-url="URL_TO_YOUR_API" to one of your html elements like <div> or <ul>. Content from within will be rendered as many times as there are rows in the spreadsheet (excluding the first row, which are column names). Each time a new row is rendered, you can refer to any value using the braces notation: {{column_name}}. Of course you can use html to style the result.

Check out the example below:

  <tbody data-sheetdb-url=""
<script src=""></script>

And this is unstyled result:

ID Name Age Comment
{{id}} {{name}} {{age}} {{comment}}

We used additional attributes to sort the result by age in descending order. The only required attribute is data-sheetdb-url. Here is the list of optional attributes:

  • data-sheetdb-limit – The number of rows that should be returned
  • data-sheetdb-offset – Row from which it should start (how many rows to skip)
  • data-sheetdb-search – You can search for specific data in your sheet. If you want to use more than one condition join them using & symbol. Example: search="name=Tom&age=15"
  • data-sheetdb-sheet - Specify the sheet (tab) you want to work with
  • data-sheetdb-sort-by – The column you want to sort by
  • data-sheetdb-sort-order – sort in asc or desc order
  • lazy-loading – if you add this attribute, the api call will be executed only when the user reaches the point of the table

There are also attributes for slots and query strings. Read below to find our what they can do for you.

Query strings

Imagine you only want to display one row per one URLs. Let's use the same spreadsheet but Large tab this time. We will use url parameters to determine whitch id user wants to display. If we do not specify id, the content will not be displayed. We also want to make sure that we will display only one row so we will use limit attribute. Here is our code:

<div data-sheetdb-url=""
    <img src="{{img}}"><br>
    {{name}} ({{id}})<br>
    Score: {{score}}
Add id to the query string to see content. Example: ?id=1

Pay attention to the url. If there are no query attributes, script does not render any content. But when you add for example ?id=5 or ?id=29 the content will be downloaded from the API. Try to change it for this page and look what will happened after page reloads.

You can also make a simple form that will add id attribute like this:

  <label for="sheetdb-id">Enter ID:</label>
  <input for="sheetdb-id" type="text" name="id">
  <button type="submit" type="button">Submit</button>

You have to be explicit what you want to filter by using data-sheetdb-query-string="id" attribute. Without this code script will download all the content (in this example limited to one by attribute data-sheetdb-limit="1").

You can use it to display your products or other content. You can even put URL's or HTML inside spreadsheet, this is easy CMS to work with.


If you want to use content of spreadsheet in different places you can use the Slots feature. Just add data-sheetdb-save="name_of_the_slot" to save its content and in different places you can use data from that slot. Just remember to add data-sheetdb-slot="name_of_the_slot" to the parent elements. Let's try it.

<div data-sheetdb-url=""
    <img src="{{img}}"><br>
    {{name}} ({{id}})<br>
    Score: {{score}}

... any other code

<div data-sheetdb-slot="current_user">
    Your email address is: {{email}}
    <!-- this div knows email thanks to the slot named `current_user` -->

{{name}} ({{id}})
Score: {{score}}
... any other code
Your email address is: {{email}}

If you want to submit data to a spreadsheet check out this example: submit data to a spreadsheet with HTML form.

Have question?

If you have any questions feel free to ask us via chat or .