Create Content Type using JavaScript object model (jsom) in SharePoint Online/2013/2016

This jsom SharePoint tutorial explains, how to create a content type using the JavaScript object model (jsom) in SharePoint Online Office 365 or SharePoint 2013/2016.

If you are new to content type then check out an article on Content type in SharePoint 2016/2013/Online tutorial.

Create Content Type using JSOM in SharePoint

For this particular example I have added a script editor web part and in the script editor web part in a SharePoint web part page.

Here, I have taken a button and on button click, it will create the content type in SharePoint site.

<script src="" type="text/javascript"></script>

<script type="text/javascript">
var contentTypeCollection;

function createContentType() {
var clientContext = new SP.ClientContext.get_current();
if (clientContext != undefined && clientContext != null) {
var web = clientContext.get_web();
this.contentTypeCollection = web.get_contentTypes();
this.contentType = contentTypeCollection.getById("0x0101");
var newContentType = new SP.ContentTypeCreationInformation();
newContentType.set_name('My Custom Content Type');
newContentType.set_description('My custom content type');
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded() {
alert("Content Type created successfully")

function onQueryFailed(sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

<input id="btnCreateContentType" onclick="createContentType()" type="button" value="Create Content Type" />

Once you clicked on the button the content type will get created. You can see the content type from the site settings page. Go to site settings -> then click on “Site content types” which is under Web Designer Galleries. Then you can see your content type like below:

create content type using JavaScript sharepoint

You may like following SharePoint content type tutorials:

This is how we can create a content type using jsom in SharePoint 2013/2016 or SharePoint Online.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.