Every post has an ID field, you can use get_the_ID() function to get the ID of every post. Or you can introduce your own ID variable and like $i = 1; and the increment by 1 $i++ before the while loop ends and use $i in ID attribute.